|
I'm using data persistence to load a GUI onto a player's screen when they spawn. It is used like this:
game.Players.PlayerAdded:connect(function(plr)
plr:WaitForDataReady()
plr.CharacterAdded:connect(function()
--load gui and stuff
end)
end)
The problem is CharacterAdded is not firing the first time a player spawns. However, if you reset your character, it will fire and load the GUI with no problems. Does anyone know why this is happening? |
|
|
Never mind, I figured it out. The WaitForDataReady was yielding the script and causing it to not recognize the first spawn. |
|
cntkillmeJoin Date: 2008-04-07 Post Count: 49450 |
Probably because by the time the dataready property is ready, the character has been added. If you don't plan on using Data Persistence then remove that part |
|
|
@cnt
The problem is I am using Data Persistence. Taking away the wait for data makes it work, I just hope it doesn't cause any load issues :/
|
|
|
Yeah, taking away the WaitForDataReady is causing issues. What should I do? :/ |
|
SasayakiJoin Date: 2007-06-29 Post Count: 33868 |
Put that code inside the CharacterAdded code. |
|
|
Maybe put the WaitForDataReady inside the CharacterAdded? |
|
|
cntkillmeJoin Date: 2008-04-07 Post Count: 49450 |
Just do this:
game.Players.PlayerAdded:connect(function(plr)
plr:WaitForDataReady()
if plr.Character then
--load gui and stuff
end
plr.CharacterAdded:connect(function()
--load gui and stuff
end)
end)
or something more efficient, or course |
|
|
cntkillmeJoin Date: 2008-04-07 Post Count: 49450 |
Nah, it would be better to do it only the first time they respawn otherwise you are just being inefficient. |
|
|
@cnt
Making it check the first time doesn't work because the character loads first. I don't think it will be very inefficient, because the game doesn't involve death unless the player resets. |
|
|
There's ways around these issues. For example:
Breakable:
game.Players.PlayerAdded:connect(function(p) -- If player joins early, no print.
print (p.Name .. " arrived")
--stuff
game.Players.CharacterAdded:connect(function(c) -- Same here, but with characters
print (c.Name .. " respawned")
end)
end)
This is a little better, because it connect already added players/characters:
function charAdded(c)
print (c.Name .. " respawned")
end
function newPlayer(p)
print (p.Name .. " arrived")
--stuff
game.Players.CharacterAdded:connect(charAdded)
if p.Character then charAdded(p.Character)
end
game.Players.PlayerAdded:connect(newPlayer)
for _,v in pairs (game.Players:GetChildren()) do
newPlayer(v)
end
Something like that :P |
|
SasayakiJoin Date: 2007-06-29 Post Count: 33868 |
Best solution is simply using DataStore over DataPersistance.... |
|
cntkillmeJoin Date: 2008-04-07 Post Count: 49450 |
'Making it check the first time doesn't work because the character loads first. I don't think it will be very inefficient, because the game doesn't involve death unless the player resets.'
That's why I told you to check whether the character has already been added, or even better:
game.Players.PlayerAdded:connect(function(plr)
plr.CharacterAdded:connect(function()
--load gui and stuff
end)
plr:WaitForDataReady()
end)
If you plan on only saving stuff after
And it's unneeded calling of a function, which is inefficient--negligibly but still, inefficient |
|
|
^wazap
I'm a noob and have never used DataStore. I got the load to work and I don't really feel like changing my method :P |
|