Remote events firing late while moving, and firing normally when not moving

Hey all, having some trouble with firing a remote event from the User Input Service, and it’s really weird. So, pretty much whenever I move the remote event fires super late for some reason, and decides not to work. I don’t understand what is going on here, please help me out.

Code:

--Services
local uis = game:GetService("UserInputService")
local players = game:GetService("Players")

--Variables
local player = players.LocalPlayer
local character = player.Character
local humanoid = character:WaitForChild("Humanoid")
local gui = script.Parent
local onEvent = game.ReplicatedStorage:FindFirstChild("BlindfoldOnAnim")
local offEvent = game.ReplicatedStorage:FindFirstChild("BlindfoldOffAnim")
local colorCorrection = game.Lighting.ColorCorrection

--Integers
local actCount = 1

--Bools
local debounce = false

--Script
uis.InputBegan:Connect(function(inpObj, gpe)
	if gpe then return end
	if debounce == true then return end

	debounce = true
	
	if inpObj.KeyCode == Enum.KeyCode.R then
		humanoid.WalkSpeed = 0
		humanoid.JumpHeight = 0
		actCount += 1
		print(actCount)
		if actCount == 1 then
			onEvent:FireServer()
			colorCorrection.Enabled = false
		else
			actCount = 0
			offEvent:FireServer()
			colorCorrection.Enabled = true
		end	

		task.wait(1)
		humanoid.WalkSpeed = 16
		humanoid.JumpHeight = 10
		debounce = false
	end
end)

The remote events are literally just animations that play on the client, and disable an accessory I added to the player. I also realized it was most likely a problem with the local script.

It’s most likely because you are setting the debounce to true before you check if the input the player is doing is the correct one, you are turning the debounce on every time you press a key, instead of every time you press the “R” key.

--Services
local uis = game:GetService("UserInputService")
local players = game:GetService("Players")

--Variables
local player = players.LocalPlayer
local character = player.Character
local humanoid = character:WaitForChild("Humanoid")

--local gui = script.Parent
local onEvent = game.ReplicatedStorage:FindFirstChild("BlindfoldOnAnim")
local offEvent = game.ReplicatedStorage:FindFirstChild("BlindfoldOffAnim")
--local colorCorrection = game.Lighting.ColorCorrection

--Integers
local actCount = 1

--Bools
local debounce = false

--Script
uis.InputBegan:Connect(function(inpObj, gpe)
	if gpe then return end
	if debounce == true then return end

	if inpObj.KeyCode == Enum.KeyCode.R then
		
		debounce = true -- Put the debounce here
		
		humanoid.WalkSpeed = 0
		humanoid.JumpHeight = 0
		actCount += 1
		print(actCount)
		if actCount == 1 then
			onEvent:FireServer()
			--colorCorrection.Enabled = false
		else
			actCount = 0
			offEvent:FireServer()
			--colorCorrection.Enabled = true
		end	

		task.wait(1)
		humanoid.WalkSpeed = 16
		humanoid.JumpHeight = 10
		debounce = false
	end
end)

Let me know if this is what you meant, or if I’m misunderstanding the question here.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.