Need help with make if player die respawn in last stage he go (obby stages)

player.respawnlocation = 3 but player spawn on video

Screenshot 2021-07-11 030245

this is my script

local player = game.Players.LocalPlayer
local PetGui = game.ReplicatedStorage.PetGui
local stats = player:WaitForChild("leaderstats")
player.character.Humanoid.Died:connect(function()
	player.leaderstats.Deaths.Value = player.leaderstats.Deaths.Value +1
	player.RespawnLocation = workspace.Checkpoints[tostring(stats.Stage.Value)]
	if player.leaderstatsP.FirePet.Value == 1 then
		player.leaderstatsP.FirePet.Value = 2	
		player.PlayerGui.PetGui:Destroy()
		game.StarterGui.PetGui:Destroy()
		local clone = PetGui:Clone()
		clone.Parent = game.StarterGui
		local clone2 = PetGui:Clone()
		clone2.Parent = player.PlayerGui
		if player.PlayerGui.ShopGui.Enabled == true then
		player.PlayerGui.PetGui.Enabled = true
		game.StarterGui.PetGui.Enabled = true
	end
end
end)

I think you forgot an end) at the end of the function.

thats not all the script but this is the part who i get problems on it but no problem with ends

this is the full script

local player = game.Players.LocalPlayer
local PetGui = game.ReplicatedStorage.PetGui
local stats = player:WaitForChild("leaderstats")
player.character.Humanoid.Died:connect(function()
	player.leaderstats.Deaths.Value = player.leaderstats.Deaths.Value +1
	player.RespawnLocation = workspace.Checkpoints[tostring(stats.Stage.Value)]
	if player.leaderstatsP.FirePet.Value == 1 then
		player.leaderstatsP.FirePet.Value = 2	
		player.PlayerGui.PetGui:Destroy()
		game.StarterGui.PetGui:Destroy()
		local clone = PetGui:Clone()
		clone.Parent = game.StarterGui
		local clone2 = PetGui:Clone()
		clone2.Parent = player.PlayerGui
		if player.PlayerGui.ShopGui.Enabled == true then
		player.PlayerGui.PetGui.Enabled = true
		game.StarterGui.PetGui.Enabled = true
	end
end
end)

You should probably add this into a characteradded function so it updates the character and doesnt only work the first time the player dies.

local player = game.Players.LocalPlayer
local PetGui = game.ReplicatedStorage.PetGui
local stats = player:WaitForChild("leaderstats")

player.CharacterAdded:Connect(function(char)
    char:WaitForChild("Humanoid").Died:connect(function()
        player.leaderstats.Deaths.Value = player.leaderstats.Deaths.Value +1
        player.RespawnLocation = workspace.Checkpoints[tostring(stats.Stage.Value)]
        if player.leaderstatsP.FirePet.Value == 1 then
            player.leaderstatsP.FirePet.Value = 2	
            player.PlayerGui.PetGui:Destroy()
            game.StarterGui.PetGui:Destroy()
            local clone = PetGui:Clone()
            clone.Parent = game.StarterGui
            local clone2 = PetGui:Clone()
            clone2.Parent = player.PlayerGui
            if player.PlayerGui.ShopGui.Enabled == true then
                player.PlayerGui.PetGui.Enabled = true
                game.StarterGui.PetGui.Enabled = true
            end
        end
    end)
end)

Edit: nvm, you said you put it in StarterCharacterScripts.

still dont work :frowning:

Here’s an example of a script in server script service of moving a player’s spawn location Player | Roblox Creator Documentation (at the bottom of the page)

yes i saw it and still dont work

You might only be able to change the spawn location on a server script.

look bro the script work but it spawn player on void not in stage 3

Screenshot 2021-07-11 030245 Screenshot 2021-07-11 030216

i tried to change the respawnlocation in server and clinet but player still spawn in void

It’s not changing the spawn location because it is a local script, change the script to a local script and do this:

function setspawn(player)
    player.RespawnLocation = workspace.Checkpoints[tostring(player.leaderstats.Stage.Value)]
end)

game.Players.PlayerAdded:Connect(function(player)
    setspawn(player)
    player.CharacterAdded:Connect(function(char)
        char:WaitForChild("Humanoid").Died:Connect(function()
            player.leaderstats.Deaths.Value = player.leaderstats.Deaths.Value +1
            setspawn(player)
        end)
    end)
end)

Also, you’ll still need to do the player with the playergui on the client so it doesnt affect others.

where i put it sssssssssssssss

Put it in ServerScriptService.

You mean change to script right? Not local script.

still dont work xxxxxxxxxxxxxxxxxxxxxx

i will make new topic and write more informations