Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Player does not spawn on specific cordinations?

I want my script to respawn players 1 second after they died and make them spawn where they died.

I made the wait part however, Now just the spawn part.

CFrames and positions are soo weird.

Can you PLEASE help me?

local respawnDelay = 1
game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character)
        character:WaitForChild("Humanoid").Died:Connect(function()
			local lastPos = character:FindFirstChild("HumanoidRootPart").CFrame + Vector3.new(0,6,0)
            wait(respawnDelay)
            if player.Parent then
				if lastPos then
					character.HumanoidRootPart.CFrame = lastPos
				end
                player:LoadCharacter()
            end
        end)
    end)
    player:LoadCharacter()
end)

2 comments

0

Try positioning them after you load their character instead of before

0

@cowsoncows did not work

2 answers

I tried your code, and it indeed not work. So, what I did is revised it a little bit and re-defined the character after it was respawned, and that seemed to work.

game.Players.PlayerAdded:Connect(function(player)
	local character = player.Character or player.CharacterAdded:Wait()
	
	if character then
		character:WaitForChild("Humanoid").Died:Connect(function()
			local lastPos = character:WaitForChild("HumanoidRootPart").CFrame
			print(lastPos)
			wait(1)
			player:LoadCharacter()
			wait(1)
			local newCharacter = player.Character or player.CharacterAdded:Wait()
			newCharacter:WaitForChild("HumanoidRootPart").CFrame = lastPos
			local newPos = newCharacter:WaitForChild("HumanoidRootPart").CFrame
			print(newPos)
		end)
	end
end)

This worked for me, if this works for you, let me know by selecting this as an answer!

3 comments

0

This will only work the first time they respawn, however. You would need to reconnect the died event to the new character.

0

aND HOW DO U DO THAT

0

Just add another newCharacter:WaitForChild("Humanoid").Died:Connect(function() again

killerbrenden is correct in saying you need the reference to the new character to be able to teleport them when they spawn. However, you also need to reconnect the died event to that same character otherwise you will only respawn in the correct place one time. Here is an updated script that should accomplish what you're looking for:

local RunService = game:GetService("RunService")

game.Players.PlayerAdded:Connect(function(player)
    local lastPosition 

    player.CharacterAdded:Connect(function(character)
		if lastPosition then
			RunService.Stepped:Wait() 
			character.HumanoidRootPart.CFrame = lastPosition
		end
        character:WaitForChild("Humanoid").Died:Connect(function()
            lastPosition = character.HumanoidRootPart.CFrame
            print(lastPosition)
			wait(1)
			player:LoadCharacter()
        end)
	end)
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.