I know there has been similar topics, however they didn’t give a very thorough answer. When I write R in chat-game, it resets me and that’s obviously not what I want. I know there’s a way to fix this, although If someone could explain how I could achieve this, that’d be awesome! Thanks.
Resetting code, although it works, just in-case you need it:
local player = game.Players.LocalPlayer
local character = player.Character
local enabled = true
local userinputservice = game:GetService("UserInputService")
userinputservice.InputBegan:connect(function(input)
if input.KeyCode == Enum.KeyCode.R and enabled then
character.Head:Remove()
enabled = false
warn(player.Name.." has been reset successfully!")
wait(6)
enabled = true
end
end)
The UserInputService InputBegan passes a second argument, which is a gameProcessed event. It is true if the game engine had noticed that input internally and taken a act on it (as it says on the API Reference).
userinputservice.InputBegan:connect(function(input, gameProcessedEvent)
if gameProcessedEvent then
return
end
if input.KeyCode == Enum.KeyCode.R and enabled then
character.Head:Remove()
enabled = false
warn(player.Name.." has been reset successfully!")
wait(6)
enabled = true
end
end)
Also :connect is Deprecated I believe, use :Connect instead now.
Doesn’t work. It’s placed in StarterCharacterScripts.
local player = game.Players.LocalPlayer
local character = player.Character
local enabled = true
local userinputservice = game:GetService("UserInputService")
userinputservice.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.R and enabled then
character.Head:Remove()
enabled = false
warn(player.Name.." has been reset successfully!")
wait(6)
enabled = true
end
end)
local character = player.Character
local db = true
local UIS = game:GetService("UserInputService")
userinputservice.InputBegan:Connect(function(input, gameProcessedEvent)
if gameProcessedEvent then
return
end
if input.KeyCode == Enum.KeyCode.R and enabled then
character.Head:Remove()
enabled = false
warn(player.Name.." has been reset successfully!")
wait(6)
enabled = true
end
end)
local player = game.Players.LocalPlayer
local character = player.Character
local enabled = true
local userinputservice = game:GetService("UserInputService")
userinputservice.InputBegan:Connect(function(input, gameProcessedEvent)
if gameProcessedEvent then
return
end
if input.KeyCode == Enum.KeyCode.R and enabled then
character.Head:Remove()
enabled = false
warn(player.Name.." has been reset successfully!")
wait(6)
enabled = true
end
end)
Also, this might just not work at all. After the player dies once, the code will stop working. Because you didn’t update the char variable, meaning, try this:
local plr = game.Players.LocalPlayer
local UIS = game:GetService("UserInputService")
UIS.InputBegan:Connect(function(Input, UIInteracting)
local char = plr.Character or plr.CharacterAdded:Wait()
if UIInteracting then
return
end
if Input.KeyCode == Enum.KeyCode.R then
char.Health = 0
end
end)
Which the difference is that it creates a char variable everytime the player runs a input, meaning it’ll always be new.
Of course later, you’ll have to change it for your preferences, aka, for it to work your way.
Reply: Oh, that’s strange, nevermind then, keep using your own code.
Its not strange, it is a script in StarterCharacterScripts, means everytime a player is spawned the Scripts are cloned into the Character again, so it will be reinitialized anyways.