I have a checkpoint system relying on spawnlocations, however when the players join the game, the player spawns a random checkpoint instead of the intended checkpoint.
ServerScriptStorage
ServerStorage = game:GetService("ServerStorage")
game.Players.PlayerAdded:Connect(function(p)
p.CharacterAdded:Connect(function(c)
if ServerStorage:FindFirstChild('CheckPointFolder') then
else
local Folder = Instance.new('Folder')
Folder.Name = 'CheckPointFolder'
Folder.Parent = game:GetService('ServerStorage')
end
if ServerStorage.CheckPointFolder:FindFirstChild(p.UserId) then
else
local PlayerStats = Instance.new('Folder')
PlayerStats.Name = p.UserId
PlayerStats.Parent = ServerStorage:WaitForChild('CheckPointFolder')
local CheckPointData = Instance.new('ObjectValue')
CheckPointData.Name = 'CheckPoint'
CheckPointData.Parent = PlayerStats
if CheckPointData.Value == nil then
CheckPointData.Value = workspace.Checkpoints.One
end
end
end)
end)
game.Players.PlayerRemoving:Connect(function(p)
ServerStorage:WaitForChild('CheckPointFolder'):WaitForChild(p.UserId):Destroy()
end)
StarterCharacterScripts
ServerStorage = game:GetService("ServerStorage")
Storage = ServerStorage.CheckPointFolder
script.Parent:WaitForChild('Humanoid').Touched:Connect(function(Hit)
if Hit:IsA('SpawnLocation') then
if script.Parent:WaitForChild('Humanoid').Health > 0 then
local Player = game.Players:GetPlayerFromCharacter(script.Parent)
Storage:WaitForChild(Player.UserId).CheckPoint.Value = Hit
Player.RespawnLocation = Storage:WaitForChild(Player.UserId).CheckPoint.Value
else
end
end
end)
Any clue why its not working as intended

5 comments
I didn't plan for it to save, but I could use this
oh. but you had a PlayerRemoving event so I assumed you wanted it to save but ok
makes sense to misunderstand, but I could make it save by not having setAsync to save data.
probably
yeh but then you'd have to get rid of the GetAsync and stuff.