Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

My script to make a checkpoint to re spawn the player doesn't work. Why?

I am trying to make a game with checkpoints in it. i made the script but when you try touching the checkpoint and then dying to see if it works it doesn't. No error's no nothing.

Here is the script:

local checkpoint = script.Parent
function OnCheckpoint(part)
	if part.Parent and part.Parent:FindFirstChild("Hunanoid") then
		local plr = game.Players:GetPlayerFromCharacter(part.Parent)
		local checkpointData = game.ServerStorage:FindFirstChild("checkpointData")
		if not checkpointData then
			checkpointData = Instance.new("Model")
			checkpointData.Parent = game.ServerStorage
			checkpointData.Name = "CheckpointData"
		local savedCheckpoint = checkpointData:FindFirstChild(player.Name)
		if not savedCheckpoint then
			savedCheckpoint = Instance.new("ObjectValue")
			savedCheckpoint.Parent = checkpointData
			savedCheckpoint.Name = player.Name
			function SpawnToCheckpoint(character)
				wait()
				local location = savedCheckpoint.Value.CFrame
				character:WaitForChild("HumanoidRootPart").CFrame = location + Vector3.new(0, 4, 0)
				print("cool")
			end
			player.CharacterAdded:Connect(SpawnToCheckpoint)
		end
		savedCheckpoint.Value = checkpoint
	end
end
checkpoint.Touched:Connect(OnCheckpoint)
end

1 comment

0

plz answer

1 answer

Hello walvie! insert a Script inside the checkpoint part, this is fixed Script:

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)

4 comments

0

this is a free model script, and it has been proven to glitch: https://www.roblox.com/library/508010193/Scripted-Checkpoint.                                     You also shouldn't be just giving a script with no explanation for how it works and why theirs did not

1

Check Roblox Studio projects before you talk, also this script working without any problems!

0

-1 and unacceptong because you did not explain at all.

This discussion is preserved as it was. New answers, comments, and votes are closed.