Hello! I have this checkpoint system, but it doesn’t work. It doesn’t spawn the player to the designated checkpoint.
local mps = game:GetService("MarketplaceService")
local dss = game:GetService("DataStoreService")
local Folder_Stage = workspace:WaitForChild("Stages")
local MoneyStore = dss:GetDataStore("Money Data!")
local RobuxStore = dss:GetDataStore("Robux Data!")
local player = game:GetService("Players")
player.PlayerAdded:Connect(function(plr)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = plr
local Money = Instance.new("NumberValue")
Money.Name = "Money"
Money.Parent = leaderstats
local Stages = Instance.new("NumberValue")
Stages.Name = "Stages"
Stages.Parent = leaderstats
Stages.Value = 1
local Robux = Instance.new("NumberValue")
Robux.Name = "Robux"
Robux.Parent = plr
plr.CharacterAdded:Connect(function(char)
wait()
if Stages.Value > 1 then
char:MoveTo(Folder_Stage:FindFirstChild(Stages.Value - 1).Position)
end
end)
end)
for i, v in pairs(Folder_Stage:GetChildren()) do
v.Touched:Connect(function(hit)
local hum = hit.Parent:FindFirstChild("Humanoid")
if hum then
local char = hit.Parent
local plr = player:GetPlayerFromCharacter(char)
local Stages = plr.leaderstats.Stages
if tonumber(v.Name) == Stages.Value then
Stages.Value += 1
end
end
end)
end
player.PlayerRemoving:Connect(function(plr)
-- Imma do some code later here
end)
So what a problem can be, is that with creating things between the PlayersAdded and the CharacterAdded can make the CharacterAdded function not run, because the delay is to big. In other words, the player already loaded in when you are connecting to the event to the first time. If thats not your problem and you are certain that this event works, we need to know more informations about what Stages.Value excatly is. What I also noticed, but not maybe in relation with your problem, is that you are using WaitForChild() in a ServerScript. When you are sure that something exists, then dont use WaitForChild() on it in the Server, it will only make your Script yield and for Example can interrupt the player.PlayerAdded Event. There are better methods to detect if sth exists or not.
EDIT:
Just saw what Stages.Value is… Sry about that. Well I think that you have to convert it into a string because its a NumberValue, so tostring(Stages.Value - 1). Also, if that doesnt work, try a for loop:
for i, v in pairs(Folder_Stage:GetChildren() do
if v.Name == tostring(Stages.Value - 1) then
char:MoveTo(v.Position)
end
end
I’ve changed it to a INT value, and removed WaitForChild. It still doesn’t work.
local mps = game:GetService("MarketplaceService")
local dss = game:GetService("DataStoreService")
local Folder_Stage = workspace.Stages
local MoneyStore = dss:GetDataStore("Money Data!")
local RobuxStore = dss:GetDataStore("Robux Data!")
local player = game:GetService("Players")
player.PlayerAdded:Connect(function(plr)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = plr
local Money = Instance.new("NumberValue")
Money.Name = "Money"
Money.Parent = leaderstats
local Stages = Instance.new("IntValue")
Stages.Name = "Stages"
Stages.Parent = leaderstats
Stages.Value = 1
local Robux = Instance.new("NumberValue")
Robux.Name = "Robux"
Robux.Parent = plr
plr.CharacterAdded:Connect(function(char)
wait()
if Stages.Value > 1 then
char:MoveTo(Folder_Stage:FindFirstChild(Stages.Value - 1).Position)
end
end)
end)
for i, v in pairs(Folder_Stage:GetChildren()) do
v.Touched:Connect(function(hit)
local hum = hit.Parent:FindFirstChild("Humanoid")
if hum then
local char = hit.Parent
local plr = player:GetPlayerFromCharacter(char)
local Stages = plr.leaderstats.Stages
if tonumber(v.Name) == Stages.Value then
Stages.Value += 1
end
end
end)
end
player.PlayerRemoving:Connect(function(plr)
end)
I recently made a working checkpoint system with an option to skip stages. I can provide you with the code and modify it to fit your game, if you like.
local mps = game:GetService("MarketplaceService")
local dss = game:GetService("DataStoreService")
local Stage_Store =dss:GetDataStore("Stage Data!")
local MoneyStore = dss:GetDataStore("Money Data!")
local RobuxStore = dss:GetDataStore("Robux Data!")
local player = game:GetService("Players")
local Folder_Stage = workspace:WaitForChild("Stages")
function PlrToStage(plr)
repeat wait() until plr.Character.HumanoidRootPart
local StagePart = Folder_Stage:FindFirstChild(tostring(plr.leaderstats.Stage.Value))
plr.Character.HumanoidRootPart.CFrame = StagePart.CFrame + Vector3.new(0,2.5,0) -- CFrame is NIL
end
player.PlayerAdded:Connect(function(plr)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = plr
local Money = Instance.new("NumberValue")
Money.Name = "Money"
Money.Parent = leaderstats
local Stages = Instance.new("IntValue")
Stages.Name = "Stage"
Stages.Parent = leaderstats
local Robux = Instance.new("NumberValue")
Robux.Name = "Robux"
Robux.Parent = plr
local Success, errormsg = pcall(function()
Stages.Value = Stage_Store:GetAsync(plr.UserId)
end)
if Success then
print("Success!")
else
warn(errormsg)
end
if plr.Character then
PlrToStage(plr)
end
plr.CharacterAdded:Connect(function()
PlrToStage(plr)
end)
end)
player.PlayerRemoving:Connect(function(plr)
local success, errormsg = pcall(function()
Stage_Store:SetAsync(plr.UserId, plr.leaderstats.Stage.Value)
end)
if success then
print("Success")
else
warn(errormsg)
end
end)
for i, v in pairs(Folder_Stage:GetChildren()) do
v.Touched:Connect(function(hit)
local hum = hit.Parent:FindFirstChild("Humanoid")
if hum then
local char = player:GetPlayerFromCharacter(hit.Parent)
local Stage_Num = tonumber(v.Name)
if char.leaderstats.Stage.Value < Stage_Num then
char.leaderstats.Stage.Value = Stage_Num
end
end
end)
end