Resetting while chatting

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)
1 Like

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.

Basically, it has a second argument, passed down a boolean, determining whether or not does, when the input began, there was a interaction with GUIs.

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)

Have you noticed that you have two InputBegan connections doing the same thing except the first one isn’t needed, could you remove that.

Still doesn’t work, oof.

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)

Seems to work on my end, could you specify what is not working / any errors?

2 Likes

Forgot to put it in StarterCharacterScripts, whoops. Thanks! It’s like 1 am here and I can barely function.

1 Like

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.

1 Like

Works fine for me, I tried typing R in chat and then reset and it still worked after that.

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.

The code I’ve seen here:

Didn’t seem to reference character as script.Parent. Sorry for misunderstanding.