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
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.
1 | game:GetService( "UserInputService" ).InputBegan:Connect( function (input, gameProcessedEvent) |
2 | if input.KeyCode = = Enum.KeyCode.R and not gameProcessedEvent then |
3 | game:GetService( "ReplicatedStorage" ).ResetCharacterEvent:FireServer() |
4 | end |
5 | 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.
1 | game:GetService( "ReplicatedStorage" ).ResetCharacterEvent.OnServerEvent:Connect( function (player) |
2 | player.Character:BreakJoints() |
3 | 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.
1 | --Make It A LocalScript |
2 |
3 | local Player = game.Players.LocalPlayer.Character |
4 | local UIS = game:GetService( "UserInputService" ) |
5 | UIS.InputBegan:Connect( function (Input) |
6 | if Input.KeyCode = = Enum.KeyCode.R then |
7 | Player.Humanoid.Health = 0 |
8 | end |
9 | 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
01 | local val = script.Val.Value |
02 | local Player = game.Players.LocalPlayer.Character |
03 | local UIS = game:GetService( "UserInputService" ) |
04 | UIS.InputBegan:Connect( function (Input) |
05 | if Input.KeyCode = = Enum.KeyCode.R and val = = 0 then |
06 | Player.Humanoid.Health = 0 |
07 | val = 1 |
08 | wait( 15 ) |
09 | val = 0 |
10 | end |
11 | end ) |
Also to make them HOLD R for a few secs to reset then do
01 | --Also a LocalScript |
02 | local Health = game.Players.LocalPlayer.Humanoid.Health |
03 | game:GetService( "UserInputService" ).InputBegan:Connect( function (inpObj, GP) |
04 | if inpObj.KeyCode = = Enum.KeyCode.R then |
05 | i = i + 1 |
06 | local tmpVal = I |
07 | wait( 3 ) |
08 | Health = 0 |
09 | local held = true |
10 | local con |
11 | con = inpObj.Changed:Connect( function (prop) |
12 | if prop = = "UserInputState" then |
13 | con:Disconnect() |
14 | held = false |
15 | return |
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.
1 | local Player = game.Players.LocalPlayer |
2 | function Keybinds(KeyCode) |
3 | if KeyCode.KeyCode = = Enum.KeyCode.R then |
4 | player.Humanoid.Health = = 0 |
5 | end |
Hello, this would be how you do it:
01 | --local script: |
02 | local debounce = false --The player can only reset once per 6 seconds |
03 | game:GetService( "UserInputService" ).InputBegan:Connect( function (key) |
04 | if key.KeyCode = = Enum.KeyCode.R and debounce = = false then |
05 | debounce = true |
06 | game.ReplicatedStorage.reset:FireServer() --add a remote event in the replicated storage, and call it reset |
07 | wait( 6 ) |
08 | debounce = false |
09 | end |
10 | end ) |
Add a remote event in the replicated storage called "reset".
1 | --Server Script |
2 | game.ReplicatedStorage.reset.OnServerEvent:Connect( function (plr) |
3 | plr.Character:BreakJoints() --break joints kills the player |
4 | end ) |
Hope that helps!