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

How Can I Add A Respawn Keyboard Shortcut?

Asked by 4 years ago

So... I Want To Make It So The Player Can Reset His Character While In-Game (Not The Menu). The Keyboard Shortcut Should Be 'R'. Please Write Me A Code <3

1
This is not a request site! Thetacah 712 — 4y

4 answers

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

You'd need to use UserInputService. First, insert a LocalScript into StarterPlayer > StarterCharacterScripts. Next, insert a RemoteEvent into ReplicatedStorage and rename it to "ResetCharacterEvent". Write the following code.

game:GetService("UserInputService").InputBegan:Connect(function(input, gameProcessedEvent)
    if input.KeyCode == Enum.KeyCode.R and not gameProcessedEvent then
        game:GetService("ReplicatedStorage").ResetCharacterEvent:FireServer()
    end
end)

The InputBegan event fires when an input is pressed (Keyboard, mouse, etc.) Then there's and if statement checking if the input the player pressed is R on the keyboard and if the player isn't in chat. This would be very important, because you wouldn't want a player typing "R" in chat and getting reset.

Now, insert a regular script into ServerScriptService and write the following code in it.

game:GetService("ReplicatedStorage").ResetCharacterEvent.OnServerEvent:Connect(function(player)
    player.Character:BreakJoints()
end)

It will check if the reset event is fired (when the player presses "R") and then it will kill the player by breaking its joints.

0
Took my breaking joints script XD alexfinger21 341 — 4y
0
Wdym? I didn't take it. youtubemasterWOW 2741 — 4y
0
This Is What I Get: 18:06:42.020 - Keycode is not a valid member of InputObject User#34743 0 — 4y
0
Oops. Forgot to capitalize the "C". I've edited the post. It should work now. youtubemasterWOW 2741 — 4y
0
Bro, You Are So Helpful. You Explained Every Single Thing. Just Wow User#34743 0 — 4y
Ad
Log in to vote
1
Answered by 4 years ago
Edited 4 years ago
--Make It A LocalScript

local Player = game.Players.LocalPlayer.Character
local UIS = game:GetService("UserInputService")
UIS.InputBegan:Connect(function(Input)
    if Input.KeyCode == Enum.KeyCode.R then
        Player.Humanoid.Health = 0
    end
end)

And if you want them to have a delay between them (This is delay of 15 seconds change the wait(HOW MANY SECONDS YOU WANT) put a IntValue in the localscript and put the value to 0 and name it Val

local val = script.Val.Value
local Player = game.Players.LocalPlayer.Character
local UIS = game:GetService("UserInputService")
UIS.InputBegan:Connect(function(Input)
    if Input.KeyCode == Enum.KeyCode.R and val == 0 then
        Player.Humanoid.Health = 0
    val = 1
    wait(15)
    val = 0
    end
end)

Also to make them HOLD R for a few secs to reset then do

--Also a LocalScript
local Health = game.Players.LocalPlayer.Humanoid.Health
game:GetService("UserInputService").InputBegan:Connect(function(inpObj, GP)
    if inpObj.KeyCode == Enum.KeyCode.R then
        i = i + 1
        local tmpVal = I
        wait(3)
        Health =  0
        local held = true
        local con
        con = inpObj.Changed:Connect(function(prop)
            if prop == "UserInputState" then
                con:Disconnect()
                held = false
                return
0
Also not gona work alexfinger21 341 — 4y
0
gonna* alexfinger21 341 — 4y
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

This isn't a request site but ill make one. Try this you will have the make the players variable first Put in serverscript service or if that dosen't work put it in workspace, local script.

local Player = game.Players.LocalPlayer
function Keybinds(KeyCode)
    if KeyCode.KeyCode == Enum.KeyCode.R then
        player.Humanoid.Health == 0 
end
0
Not gonna work alexfinger21 341 — 4y
0
gonna* alexfinger21 341 — 4y
0
Updated it AmIOriginalOrNot 105 — 4y
Log in to vote
0
Answered by 4 years ago

Hello, this would be how you do it:

--local script:
local debounce = false --The player can only reset once per 6 seconds
game:GetService("UserInputService").InputBegan:Connect(function(key)
    if key.KeyCode == Enum.KeyCode.R  and debounce == false then
        debounce = true
        game.ReplicatedStorage.reset:FireServer() --add a remote event in the replicated storage, and call it reset
        wait(6)
        debounce = false
    end
end)

Add a remote event in the replicated storage called "reset".

--Server Script
game.ReplicatedStorage.reset.OnServerEvent:Connect(function(plr)
    plr.Character:BreakJoints()--break joints kills the player
end)

Hope that helps!

0
is that a bit Overcomplicated? you dont need a event AmIOriginalOrNot 105 — 4y
0
you do alexfinger21 341 — 4y
0
if he has filtering enabled, you do alexfinger21 341 — 4y
0
That would work, but it would be very annoying if you were in chat and you typed "R". It would reset your character if you did that. Also, filtering enabled is always enabled, even if you disable it in properties. youtubemasterWOW 2741 — 4y

Answer this question