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

How do I make a player respawn when they press "R"?

4 answers

✓ Accepted answer

Wow, nearly a year, well, I'll answer it since it's ez.

Make sure this is in a local script

local mouse = game.Players.LocalPlayer:GetMouse()
local player = game.Players.LocalPlayer
repeat wait() until player.Character

mouse.KeyDown:connect(function(key)
if tostring(key) == "r" then
player:LoadCharacter()
end
end)

Just destroy the players head when you press R.

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:wait()
function onKeyPress (R) character.Head:Destroy()

2 comments

0

Line 3 will not work: first off, it's missing an end, 2nd, for a function, you NEED to call on it for it to fire, 3rd, "R" isn't used anywhere else in the code (it's defined, but not used), and 4th, you don't require the extra parentheses around character & Destroy().

0

pls no

Try This Make sure its in ReplicatedFirst. This should work.


-- [[ Main Stuff ]] --
local Player = game.Players.LocalPlayer
if Player:FindFirstChild("CanLoad") then
else
	local CanLoad = Instance.new("BoolValue")
	CanLoad.Parent = Player
	CanLoad.Name = "CanLoad"
	CanLoad.Value = true
end

repeat wait()

until Player.Character ~= nil

-- [[ Functions ]] --


function Refresh()
	Player.Character.Humanoid.Died:connect(function()
	Player:FindFirstChild("CanLoad").Value = false
	RepeatWaitForRespawn()
end)
end

function RepeatWaitForRespawn()
	while Player:FindFirstChild("CanLoad").Value ~= true do wait()
		Player.Character = nil
	end
	Player:LoadCharacter(true)
	Refresh()
end




local function onKeyPress(inputObject, gameProcessedEvent)
	if inputObject.KeyCode == Enum.KeyCode.R then
Player:FindFirstChild("CanLoad").Value = true

	end
end
game:GetService("UserInputService").InputBegan:connect(onKeyPress)
Refresh()

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