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
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)