I have a checkpoint script for a difficulty chart obby I am trying to make, and it works when resetting or dying, but when a player joins it spawns them in the middle of the map instead of at the checkpoint.

--variables
local checkpoints = workspace:WaitForChild("Checkpoints")

local DataStoreService = game:GetService("DataStoreService")
local plrStage = DataStoreService:GetDataStore("StageValue")


local db = true
--when a player joins
game.Players.PlayerAdded:Connect(function(plr)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = plr
	
	local v = Instance.new("IntValue")
	v.Value = plrStage:GetAsync(plr.UserId,v) --starting stage value
	v.Name = "Stage" --name of the leaderboard stat
	v.Parent = leaderstats
	
	print("Player Data Successfully Loaded!")
	
	v.Changed:Connect(function(value)
		plrStage:SetAsync(plr.UserId,value)
		print("Player Data Successfully Saved!")
	end)
	
	plr.CharacterAdded:Connect(function(char)
		local hum = char:WaitForChild("Humanoid")
		wait()
		--\/ is supposed to spawn character at the checkpoint
		wait(char:MoveTo(checkpoints[v.Value].Position))
		
		hum.Touched:Connect(function(hit)
			
			if hit.Parent == checkpoints and char.Humanoid.Health ~= 0 then
				if tonumber(hit.Name) == v.Value +1 then --changes what stage the player is on
					v.Value = v.Value +1
				end
				
			elseif hit.Parent == workspace.Damagers then
				char.Humanoid.Health = char.Humanoid.Health - 4 --damages player when they come into contact with the brick
				db = false
				wait(0.1) --adds a wait so it doesn't kill the player too fast
				db = true
				
			elseif hit.Parent == workspace.Killers then
				char.Humanoid.Health = 0 --kills player when they come into contact with the brick
			end
		end)
	end)
	
end)

1 comment

0

Line 31, remove the wait() function. What was even the purpose?