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

Why is the checkpoint teleport script is not working? Please help me!

Asked by 4 years ago
Edited 4 years ago

I am a bit confused about my script. Because the detecting part works perfectly and the teleport command is also logical, but I when I test it then it will detect if the player died but will not teleport the player to that location.

Here is my script (print(“Success!”) is because for testing if the detecting part works):

game.Players.PlayerAdded:Connect(function(player)
    print(player)
    local spawn = false
    script.Parent.Touched:Connect(function(hit)
        print("Success!")
        if hit.Parent:FindFirstChild("Humanoid") and hit.Parent.Name == player.Name then
            spawn = true
        end
    end)
    player.CharacterAdded:Connect(function(character)
        print("Success!")
        if spawn == true then
            print("Success!")
            character.HumanoidRootPart.CFrame = CFrame.new(script.Parent.Position.X,script.Parent.Position.Y+5,script.Parent.Position.Z)
        end
    end)
end)

My script is a script, not a local or module script. If you know why it is not working, then please point it out for me. I do not need how to make a checkpoint, I just need why is this not working. If you know then please tell me, thanks.

1 answer

Log in to vote
0
Answered by 4 years ago

I have a checkpoint for my script and it's working so use that:

local Players = game:GetService("Players")
local spawn = script.Parent

script.Parent.Touched:Connect(function(hit)
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
    if hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
        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("UpperTorso").CFrame = game.ServerStorage.CheckpointData[tostring(player.userId)].Value.CFrame + Vector3.new(0, 4, 0)
            end)
        end
        checkpoint.Value = spawn
    end
end)
0
I know, but why is mine not working? Cuz mine is actually one of my friend's script, and he do not know why it does not work so he came and ask me why and I do not know so I came and ask this question. willywillycow 50 — 4y
0
I know how to make a checkpoint but just asking why is this one not working cuz it does not seem wrong. willywillycow 50 — 4y
0
I'm not familiar with teleporting and Vector, CFrames so I can't help you sry. dinko13579 35 — 4y
Ad

Answer this question