Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
walvie 12
5 years ago

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
0
plz answer walvie 12 — 5y

1 answer

Log in to vote
0
Answered by
Voxozor 162
5 years ago

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)
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 SerpentineKing 3885 — 5y
1
Check Roblox Studio projects before you talk, also this script working without any problems! Voxozor 162 — 5y
0
-1 and unacceptong because you did not explain at all. User#24403 69 — 5y
Ad

Answer this question