R to Reset and Chatting

Hi developers,

In my game I have a script that allows you to reset your character after pressing R.

The only problem is that when chatting it resets your character after typing R.

Is there any way I can disable the script when opening the chat and re-enable it upon closing it.

Many Thanks for your help

Here is the script:

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)

Pls search Having Problems with r to death - #3 by hakobmher this is my topic

My script is working, I just want to know how to disable it when the chat is opened.

Yeah, we all faced the same issue, a keybind causing an action and overriding other keybinds.

You can simply fix this by using ContextActionService

This allows to create keybinds that only work under special conditions or certain period of times, for example if I set R to reset, by default ContextAction won’t do what I set my keybind to do because the chat is open, more info on that on the link above.

Really useful and recommended in such situations like yours.

1 Like

InputBegan’s second argument is a boolean telling if the game already processed the input. I added a parameter for it and added it to the if statetement. Does it now work?

local character = player.Character 
local enabled = true 
local userinputservice = game:GetService("UserInputService") 
userinputservice.InputBegan:connect(function(input, gameProcessedEvent)
	if input.KeyCode == Enum.KeyCode.R and enabled and not gameProcessedEvent then 
		character.Head:Remove() 
		enabled = false
		warn(player.Name.." has been reset successfully!") 
		wait(6) 
		enabled = true 
	end
end)
1 Like
--Client
UIS.InputBegan:Connect(function(input, gameProcessedEvent)
	if not gameProcessedEvent then
		if input.KeyCode == Enum.KeyCode[ResetKeyBind] then
			game.ReplicatedStorage.PlayerReset:FireServer()
		end
	end
end)

--Server:
game.ReplicatedStorage.PlayerReset.OnServerEvent:Connect(function(player)
	player:LoadCharacter()
end)

This is a client-sided script, under StarterPlayer.StarterCharacterScripts.

local character = player.Character 
local db = true 
local UIS = game:GetService("UserInputService") 

UIS .InputBegan:connect(function(input, gameProcessed)
	if gameProcessed then return end

	if input.KeyCode == Enum.KeyCode.R and db and character:FindFirstChild("Humanoid") and character.Humanoid.Health ~= 0 then 
		character.Humanoid.Health = 0 
		db = false
	end
end)
1 Like

Hmmm doesn’t seem to work for me. Where do you place the scripts and are they local or normal?
Thanks

This is in starterplayerscripts and its a local script

This is in serverscriptservice and its a serverscript , you need to make sure you have the remote event.

Is this the script to reset your character?

I’m trying to make it so that the R to Reset script is disabled after opening the chat.

Sorry if I have misunderstood

Thanks

UserInputService.InputBegan has 2 parameters, the input and gameProcessedEvent.

If you are typing in a text box gameProcessedEvent will be true but if you are not it will be false.

So you do an if statement to make sure its false.

Ok I’ll try it now.

Are these scripts for disabling the R to Reset after opening the chat?

Thanks

Yes it does it checks if you are in a text box.

Do i need to make a variable before hand?

local UIS = game:GetService("UserInputService")

Yes you do, I took that from a script in my game and forgot to copy that too.

1 Like

Also, i have my R to Reset script as a LocalScript in StarterGUI

Im quite new to scripting, what is a remote event?

Thanks

Go to replicated storage, click the plus, search remote event insert it, and name it PlayerReset

Ok, is that all I have to do

Thanks

OMG! You’re making a difficulty chart too! Epic!!

1 Like

I’ve done all of the things, and its still not working, I think we have a different method of resetting a character

Many thanks anyways!