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

Why isn't my script teleporting players back to their stages in my obby?

Asked by 4 years ago
Edited 4 years ago

I am in utter confusion as of right now. I have a supposed-to-be simple script here for an obby. The problem is, it won't teleport players back to the stage they were on, and it spawns them back at the start. It saves their level, but it doesn't teleport to the level they were on after they die. There are no errors, it goes through the entire script, including the print function at the very end. Please help me understand what is going on.

local player = game.Players.LocalPlayer
game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(char)
        char:WaitForChild("Humanoid").Died:Connect(function()
            local spawnpointnum = player.leaderstats.Stage.Value
            local spawnpoint = game.Workspace.StageNumbers:FindFirstChild(tostring(spawnpointnum))
            player.CharacterAdded:Wait()
            wait(1)
            char:MoveTo(spawnpoint.Position)
            print(player.Name .. " has died!")

        end)
    end)
end)

1 answer

Log in to vote
0
Answered by 4 years ago

Hello. There is only one problem in your code.


Problem:

  • You used "LocalPlayer" in a ServerScript. "LocalPlayer" is only usable in "LocalScripts" as ServerScripts run on an actual server instead of the client.

Solution:

  • Remove the "player" variable in the main scope.

Fixed Code:

game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(char)
        char:WaitForChild("Humanoid").Died:Connect(function()
            local spawnpointnum = player.leaderstats.Stage.Value
            local spawnpoint = game.Workspace.StageNumbers:FindFirstChild(tostring(spawnpointnum))
            player.CharacterAdded:Wait()
            wait(1)
            char:MoveTo(spawnpoint.Position)
            print(player.Name .. " has died!")

        end)
    end)
end)
0
That makes total sense, however, it still isn't working for some reason. I removed the LocalPlayer line, it still goes through all of the code, it just doesn't teleport the player as it should once they respawn. BreckleShrimp 23 — 4y
0
Sure. I don't see anything wrong with it though. youtubemasterWOW 2741 — 4y
0
So I ended up messing with the CFrame and it ended up working. Thank you! BreckleShrimp 23 — 4y
0
np youtubemasterWOW 2741 — 4y
Ad

Answer this question