I used checkpoints that have already been made from the assets, they work most of the time, but sometimes they stop working on a server and when someone dies, it returns them to the initial spawn point. The server will stay in this condition, leading everyone to quit it. I am hoping this is a common problem with an easy fix.

Here is the script in the checkpoints.

local spawn = script.Parent
spawn.Touched:connect(function(hit)
	if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		local checkpointData = game.ServerStorage:FindFirstChild("CheckpointData")
		if not checkpointData then
			checkpointData = Instance.new("Model", game.ServerStorage)
			checkpointData.Name = "CheckpointData"
		end
		
		local checkpoint = checkpointData:FindFirstChild(tostring(player.userId))
		if not checkpoint then
			checkpoint = Instance.new("ObjectValue", checkpointData)
			checkpoint.Name = tostring(player.userId)
			
			player.CharacterAdded:connect(function(character)
				wait()
				character:WaitForChild("HumanoidRootPart").CFrame = game.ServerStorage.CheckpointData[tostring(player.userId)].Value.CFrame + Vector3.new(0, 4, 0)
			end)
		end
		
		checkpoint.Value = spawn
	end
end)

Thank you

2 comments

0

Why are you listening for a CharacterAdded event from a Touched event? Also, connect is deprecated, switch to Connect, userId is deprecated, switch to UserId. The parent argument to Instance.new is deprecated, assign the parent as the last property in another line

0

Also, you wouldn't need to check if "hit" and "hit.Parent" exist. The Touched event wouldn't fire if it didn't exist.