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

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

Asked by 7 years ago

I have Tried this script (i am pretty new) And it didn't kill someone

function onKeyPress (R) (h.Health = 0)

          end

Anyone know how to make it work?

0
Use userinputservice AZDev 590 — 7y
0
You can kill the player to do it but it would be better to use a remote event and use the LoadCharacter() function. AZDev 590 — 7y

4 answers

Log in to vote
0
Answered by
vkax 85
6 years ago

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)
Ad
Log in to vote
0
Answered by 7 years ago

Set the humanoid health to zero once they pressed R

Get the localplayer(well simple way)

use UserInputService

http://wiki.roblox.com/index.php?title=Keyboard_input

Log in to vote
-1
Answered by 7 years ago
Edited 7 years ago

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()
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(). TheeDeathCaster 2368 — 7y
0
pls no LightModed 81 — 7y
Log in to vote
-1
Answered by 7 years ago
Edited 7 years ago

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()

Answer this question