|
I'm not sure why, it's not printing that a player has been found.
game.Players.PlayerAdded:connect(function(player)
repeat wait() until player~=nil
print("Player found!")
local Exp = Instance.new("IntValue",plr)
Exp.Name = "Exp"
Exp.Value = 0
local ExpNeeded = Instance.new("IntValue",plr)
ExpNeeded.Name = "ExpNeeded"
ExpNeeded.Value = 120
local lvl = Instance.new("IntValue",plr)
lvl.Name = "Level"
lvl.Value = 1
local cash = Instance.new("IntValue",plr)
cash.Name = "Cash"
cash.Value = 0
local datastore = game:GetService("DataStoreService"):GetDataStore(player.Name.."Values")
player:WaitForChild("Exp")
player:WaitForChild("ExpNeeded")
player:WaitForChild("Level")
player:WaitForChild("Cash")
wait(1)
Exp.Value = datastore:GetAsync(Exp.Name)
ExpNeeded.Value = datastore:GetAsync(ExpNeeded.Name)
Level.Value = datastore:GetAsync(Level.Name)
Cash.Value = datastore:GetAsync(Cash.Name)
print("Stats loaded")
end) |
|
|
The event fires when a player is "added" and not "loading", so you don't need to worry about if the player has loaded or not. I think this repeat may run on endlessly. Make sure you're doing this in online mode, which you probably already aware of.
game.Players.PlayerAdded:connect(function(player)
--repeat wait() until player~=nil
print("Player found!") |
|
|
KEVEKEV77Join Date: 2009-03-12 Post Count: 6961 |
AT start
if player:GetDataReady() then |
|
|
ok i fixed it up a bit
here's what it is now
game.Players.PlayerAdded:connect(function(plr)
if plr:GetDataReady() then
print("Player found!")
local Exp = Instance.new("IntValue",plr)
Exp.Name = "Exp"
Exp.Value = 0
local ExpNeeded = Instance.new("IntValue",plr)
ExpNeeded.Name = "ExpNeeded"
ExpNeeded.Value = 120
local lvl = Instance.new("IntValue",plr)
lvl.Name = "Level"
lvl.Value = 1
local cash = Instance.new("IntValue",plr)
cash.Name = "Cash"
cash.Value = 0
local datastore = game:GetService("DataStoreService"):GetDataStore(plr.Name.."Values")
plr:WaitForChild("Exp")
plr:WaitForChild("ExpNeeded")
plr:WaitForChild("Level")
plr:WaitForChild("Cash")
wait(1)
Exp.Value = datastore:GetAsync(Exp.Name)
ExpNeeded.Value = datastore:GetAsync(ExpNeeded.Name)
Level.Value = datastore:GetAsync(Level.Name)
Cash.Value = datastore:GetAsync(Cash.Name)
print("Stats loaded")
end
end) |
|
|
i changed that line to WaitForDataReady
still isn't printing anything |
|
|
here's the entire script, if it's affecting it in some way
while wait(60) do
local m = Instance.new("Hint",Workspace)
m.Text = "Saving stats.."
for i,v in pairs(game.Players:GetPlayers()) do
local datastore = game:GetService("DataStoreService"):GetDataStore(v.Name.."Values")
local Exp = v:WaitForChild("Exp")
local ExpNeeded = v:WaitForChild("ExpNeeded")
local Level = v:WaitForChild("Level")
local Cash = v:WaitForChild("Cash")
datastore:SetAsync(Exp.Name, Exp.Value)
datastore:SetAsync(Cash.Name,Cash.Value)
datastore:SetAsync(ExpNeeded.Name,ExpNeeded.Value)
datastore:SetAsync(Level.Name,Level.Value)
print("Stats successfully saved")
end
end
game.Players.PlayerAdded:connect(function(plr)
plr:WaitForDataReady()
print("Player found!")
local Exp = Instance.new("IntValue",plr)
Exp.Name = "Exp"
Exp.Value = 0
local ExpNeeded = Instance.new("IntValue",plr)
ExpNeeded.Name = "ExpNeeded"
ExpNeeded.Value = 120
local lvl = Instance.new("IntValue",plr)
lvl.Name = "Level"
lvl.Value = 1
local cash = Instance.new("IntValue",plr)
cash.Name = "Cash"
cash.Value = 0
local datastore = game:GetService("DataStoreService"):GetDataStore(plr.Name.."Values")
plr:WaitForChild("Exp")
plr:WaitForChild("ExpNeeded")
plr:WaitForChild("Level")
plr:WaitForChild("Cash")
wait(1)
Exp.Value = datastore:GetAsync(Exp.Name)
ExpNeeded.Value = datastore:GetAsync(ExpNeeded.Name)
Level.Value = datastore:GetAsync(Level.Name)
Cash.Value = datastore:GetAsync(Cash.Name)
print("Stats loaded")
end) |
|
|
If you're testing this by "Play Solo", you're original script may be right.
If you're actually doing this you should start a server with one player.
If you still don't understand, too bad. |
|
|
"If you still don't understand, too bad."
well you're no help
so does anyone know why the PlayerAdded is not working
i'm testing it at my actual place, not playsolo or a server
it's breaking all of my other scripts that use the values
can someone please help |
|
|
DataStoreJoin Date: 2012-02-07 Post Count: 8540 |
Put the while loop at the end of the script. |
|
e_ScriphJoin Date: 2013-01-13 Post Count: 5580 |
... Press f9
BOOM mind blown.
you will see the text in dev console
- xXScriptzXx |
|
|
|
"Put the while loop at the end of the script."
where exactly |
|
DataStoreJoin Date: 2012-02-07 Post Count: 8540 |
After any functions you're expecting to run. The while loop, as it currently stands, is stopping everything else from running, which it will continue to do until it's the last thing to be ran, or the loop is broken. |
|
|
thanks a lot, everything works now |
|