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