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

How to make your character spawn where they are supposed to??

Asked by 5 years ago

I'm making an obby so I put a few spawn points for checkpoints. but everytime I die it just sends me to a random checkpoint and not the one right before I died, how do I fix this?

0
Lol who upvoted this DinozCreates 1070 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago

Make sure neutral is disaled and AllowTeamChangeOnTouch is enabled. Also try making a different team color for each checkpoint.

Ad
Log in to vote
0
Answered by
fr2013 88
5 years ago
Edited 5 years ago

Insert a normal Script in each of the parts and add the code to make the player return where they left off after they died.

local spawn = script.Parent -- Find where the part is
spawn.Touched:connect(function(hit) -- When the player touches the part
    if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") then -- If the player who touches the part is a humanoid
        local player = game.Players:GetPlayerFromCharacter(hit.Parent) -- Find any players
        local checkpointData = game.ServerStorage:FindFirstChild("CheckpointData") -- Creates some sort of Data Store
        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) -- When the player respawns
                wait()
                character:WaitForChild("HumanoidRootPart").CFrame = game.ServerStorage.CheckpointData[tostring(player.userId)].Value.CFrame + Vector3.new(0, 4, 0) -- Teleport to where they left off after they've touched the part in that position
            end)
        end

        checkpoint.Value = spawn
    end
end)
0
nice joke ya got there User#23365 30 — 5y
0
Doesn't seem invalid to me fr2013 88 — 5y

Answer this question