RemoteEvent only firing once

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want this remoteevent, once being ran 5 times, to reset the given counter

  2. What is the issue? Include screenshots / videos if possible!
    RemoteEvent is only firing once, I don’t know if it’s because of my debounce or something else within the script but I can’t get it to fire more than once.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I checked to see if it was the fault of my debounce which earned me no results, as well as various print statements to find out what is and isn’t working.

local RS = game:GetService("ReplicatedStorage")
local remoteevent = RS:WaitForChild("RemoteEvent")
print("not waiting anymore")
local debounce = false
local combo = 0
local maxcooldown = 0.5
local cooldown = 0.2

local function onfired(player)
	if not debounce then
		debounce = true
		print("fired")
		combo += 1
		print(combo)
		local rayOrigin = player.Character.HumanoidRootPart.Position
		local rayDirection = Vector3.new(0, 10, 0)
		local raycastParams = RaycastParams.new()
		raycastParams.FilterDescendantsInstances = {player.Character.Humanoid}
		raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
		local raycastResult = workspace:Raycast(rayOrigin, rayDirection, raycastParams)
		print (raycastResult.Instance)
		print("test")
		if combo == 5 then print("Reached")
			combo = 0
		wait(cooldown)
		debounce = false		
end
end
end

remoteevent.OnServerEvent:Connect(onfired)
local RS = game:GetService("ReplicatedStorage")
local UIS = game:GetService("UserInputService")
local player = game.Players.LocalPlayer

UIS.InputBegan:Connect(function(input, busy)
	if input.KeyCode == Enum.KeyCode.E and not busy then
		RS.RemoteEvent:FireServer(player)
		print("Pressed")
end
	end)
1 Like

RS.RemoteEvent:FireServer(player)
RS.RemoteEvent:FireServer()

You don’t need to pass the player object as an argument to “FireServer()”. The player object associated with the client is automatically passed as an argument to the function connected to the OnServerEvent event handler. The parameter named “player” is required to be received by the function connected to the event, to handle this passed player object.

You need to declare the local function as much times as you want the RemoteEvent to fire.

Thanks for the info, however this doesn’t solve my issue.

Also, do I need to use (player) as the parameter for the function in the server script? I’d assume such, right?

Yes, that’s necessary to handle the received player object, also do you get any errors when an attempt to fire the server for a second times occurs?

Nope, it even detects the UserInput ( it prints “Pressed” every time I press e), however the function within the server script only runs once

image
this is the output

Change this…

To this…

UIS.InputBegan:Connect(function(input, busy)
	if input.KeyCode == Enum.KeyCode.E and not busy then
		RS.RemoteEvent:FireServer(player)
		print("Pressed")
        RS.RemoteEvent:FireServer(player)
        print("Pressed")
        RS.RemoteEvent:FireServer(player)
        print("Pressed")
        RS.RemoteEvent:FireServer(player)
        print("Pressed")
        RS.RemoteEvent:FireServer(player)
        print("Pressed")
end
	end)

The print thing is optional, but you need to fire the RemoteEvent 5 times in the function.

Still only fires the RemoteEvent once, just ends up printing multiple times per press.
I’m certain it’s something to do with the code within the server script, not so much the local script

image

if input.KeyCode == Enum.KeyCode.E and not busy then
if input.KeyCode == Enum.KeyCode.E then

Still only firing once, also not busy just means it wont fire when I’m in a gui.

remoteevent.OnServerEvent:Connect(function(player)
	if not debounce then
		debounce = true
		print("fired")
		combo += 1
		print(combo)
		local rayOrigin = player.Character.HumanoidRootPart.Position
		local rayDirection = Vector3.new(0, 10, 0)
		local raycastParams = RaycastParams.new()
		raycastParams.FilterDescendantsInstances = {player.Character.Humanoid}
		raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
		local raycastResult = workspace:Raycast(rayOrigin, rayDirection, raycastParams)
		print (raycastResult.Instance)
		print("test")
		if combo == 5 then
			print("Reached")
			combo = 0
			task.wait(0.2)
			debounce = false		
		end
	end
end)

I edited your code a bit and got it working, thanks for the help!

local RS = game:GetService("ReplicatedStorage")
local remoteevent = RS:WaitForChild("RemoteEvent")
local debounce = false
local combo = 0
remoteevent.OnServerEvent:Connect(function(player)
	if not debounce then
		debounce = true
		print("fired")
		combo += 1
		print(combo)
		local rayOrigin = player.Character.HumanoidRootPart.Position
		local rayDirection = Vector3.new(0, 10, 0)
		local raycastParams = RaycastParams.new()
		raycastParams.FilterDescendantsInstances = {player.Character.Humanoid}
		raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
		local raycastResult = workspace:Raycast(rayOrigin, rayDirection, raycastParams)
		print (raycastResult.Instance)
		print("test")
		wait(1)
		debounce = false
		if combo == 5 then
			print("Reached")
			combo = 0
			debounce = true
			wait(10)
			debounce = false
		end
	end
end)