game.Players.PlayerAdded:Connect(function(player)
--// STORES \\--
local StageData = Datastore2("Stage", player)
local DeathData = Datastore2("Deaths", player)
--// CREATING INSTANCES \\--
local Stats = Instance.new("Folder"); Stats.Name = "leaderstats"; Stats.Parent = player
local Int = Instance.new("NumberValue", Stats); Int.Name = "Stage"
local D = Instance.new("NumberValue", Stats);D.Name = "Deaths"
local AddOns = Instance.new("Folder"); AddOns.Name = "AddOns"; AddOns.Parent = player
local Instant = Instance.new("BoolValue", AddOns); Instant.Name = "InstantRespawn"
local Invic = Instance.new("BoolValue", AddOns); Invic.Name = "Invincible"
--// LOAD DATA \\--
if StageData:Get() ~= nil then
Int.Value = StageData:Get()
else
Int.Value = 0
end
if DeathData:Get() ~= nil then
D.Value = DeathData:Get()
else
D.Value = 0
end
--// SAVE DATA \\--
Int.Changed:Connect(function(value)
StageData:Set(value)
end)
D.Changed:Connect(function(value)
DeathData:Set(value)
end)
--player.CharacterAdded:Connect(function(char)
--repeat wait() until player.Character
--Handler.Do(player, player.Character)
player.CharacterAdded:Connect(function(char) -- CharacterAddedFunction
--// MODULES \\--
Handler.Do(player, char)
end)
end)
So When the player First joins the game, the character Added doesn’t run, only when I die it will run it?
Am I doing something wrong? also When I die It doesn’t teleport my character to the checkpoint:
Checkpoint.Check = function(player, character)
local Stage = player:WaitForChild("leaderstats").Stage
local Checkpoint = game.Workspace:WaitForChild("Checkpoints"):WaitForChild(Stage.Value)
character:MoveTo(Checkpoint.Position)
end
There’s too much code going before it that those milliseconds of running that code leads to it connecting the “CharacterAdded” thing after the player has “Already been created”, hence not running the code unless they reset (or whenever the character gets added running the connection).
You can just run that code directly after the connection (and it’ll only run once when the player joins so you don’t have to worry about anything).
--// STORES \\--
local StageData = Datastore2("Stage", player)
local DeathData = Datastore2("Deaths", player)
--// CREATING INSTANCES \\--
local Stats = Instance.new("Folder"); Stats.Name = "leaderstats"; Stats.Parent = player
local Int = Instance.new("NumberValue", Stats); Int.Name = "Stage"
local D = Instance.new("NumberValue", Stats);D.Name = "Deaths"
local AddOns = Instance.new("Folder"); AddOns.Name = "AddOns"; AddOns.Parent = player
local Instant = Instance.new("BoolValue", AddOns); Instant.Name = "InstantRespawn"
local Invic = Instance.new("BoolValue", AddOns); Invic.Name = "Invincible"
--// LOAD DATA \\--
if StageData:Get() ~= nil then
Int.Value = StageData:Get()
else
Int.Value = 0
end
if DeathData:Get() ~= nil then
D.Value = DeathData:Get()
else
D.Value = 0
end
--// SAVE DATA \\--
Int.Changed:Connect(function(value)
StageData:Set(value)
end)
D.Changed:Connect(function(value)
DeathData:Set(value)
end)
--player.CharacterAdded:Connect(function(char)
--repeat wait() until player.Character
--Handler.Do(player, player.Character)
player.CharacterAdded:Connect(function(char) -- CharacterAddedFunction
--// MODULES \\--
Handler.Do(player, char)
end)
Handler.Do(player, char)
end)
Oh right, that makes sense. But for some reason, after I die it will not teleport me? Not sure why, it does when I first join, but after that it doesn’t teleport me.
I’m not sure quite what the problem is, the connection itself looks right though, so maybe I would use a Print(“Test”) to test if it is running the connection, if it is running the connection then the problem is to do something with the actual function itself and not the connection.
Yeah, I’m pretty sure. I ran a print to see when a character exist, if this is works? If it’s after a characterAdded shouldn’t it be a full character?
It should spawn with everything, however, I have had problems with this sort of thing in the past. Trying to use like MoveTo or SetPrimaryPartCFrame, right when the player spawns has caused me issues. I usually solve it by having some sort of slight wait