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

How Can I Add A Respawn Keyboard Shortcut?

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 comment

1

This is not a request site!

4 answers

✓ Accepted answer

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.

5 comments

0

Took my breaking joints script XD

0

Wdym? I didn't take it.

0

This Is What I Get: 18:06:42.020 - Keycode is not a valid member of InputObject

0

Oops. Forgot to capitalize the "C". I've edited the post. It should work now.

0

Bro, You Are So Helpful. You Explained Every Single Thing. Just Wow

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

2 comments

0

Also not gona work

0

gonna*

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

3 comments

0

Not gonna work

0

gonna*

0

Updated it

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!

4 comments

0

is that a bit Overcomplicated? you dont need a event

0

you do

0

if he has filtering enabled, you do

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.

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