Remote Event Firing To Many Times(Major Help)

  1. Im creating a pet system where you can equip and unequip pets.

  2. The issue is the remote event is firing to many times and messing up the game/

  3. I looked on the devforum but couldnt figure out how to fix it.

My script is down below

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local Info = script.Parent.Parent.Parent.Information

for i, v in pairs(ReplicatedStorage.Pets:GetChildren()) do
	local PetFrame = script.Parent.Parent["Pet Frame"]:Clone()
	PetFrame.Parent = script.Parent

	local Rarity = v:FindFirstChild("Rarity")
	local petName = v.Name
	print(petName)
	PetFrame.Visible = true
	PetFrame.Name = petName

	local Module3D = require(game.ReplicatedStorage:WaitForChild("Module3D"))
	local Model3D = Module3D:Attach3D(PetFrame, v:Clone())
	Model3D:SetDepthMultiplier(1.2)
	Model3D.Camera.FieldOfView = 5
	Model3D.Visible = true

	game:GetService("RunService").RenderStepped:Connect(function()
		Model3D:SetCFrame(CFrame.Angles(0, tick() % (math.pi * 2), 0) * CFrame.Angles(math.rad(-10), 0, 0))
	end)

	PetFrame.InputBegan:Connect(function(input)
		if input.UserInputType == Enum.UserInputType.MouseButton1 then
			Info.ItemName.Text = petName
			Info.Description.Text = tostring("Rarity: " .. Rarity.Value)

			local Pet = game.ReplicatedStorage.Pets:FindFirstChild(petName):Clone()
			local Model3d = Module3D:Attach3D(Info.ImageContainer.ViewportFrame, Pet)
			Model3d:SetDepthMultiplier(1.2)
			Model3d.Camera.FieldOfView = 5
			Model3d.Visible = true

			game:GetService("RunService").RenderStepped:Connect(function()
				Model3d:SetCFrame(CFrame.Angles(0, tick() % (math.pi * 2), 0) * CFrame.Angles(math.rad(-10), 0, 0))
			end)			
		end
	end)
end

Info.EquipButton.MouseButton1Click:Connect(function() 
	ReplicatedStorage.Equip:FireServer(Info.ItemName.Text)
end)

Any Help Is Good as im very stuck.

Any Help Is Good as im very stuck on this issue.

1 Like

You might want to add a debounce to the anonymous function.

local debounce = false
Info.EquipButton.MouseButton1Click:Connect(function() 
    if not debounce then end
    ReplicatedStorage.Equip:FireServer(Info.ItemName.Text)
    debounce = true
    task.wait(1)
    debounce = false
end

This limit the player firing to the server by preventing them from spamming the button.

No when I click the button once the event fires to many times

Add a print() to inside of the InputBegan function and see how many times it prints. It may be firing the remote once per every pet you have running inside of this loop.

There is no explainable reason for this given the snippet you’ve provided. The Mouse1ButtonClick event is being binded to a function once and only once, which means it should fire only once per click.

Perhaps it’s something on the server side that is causing the event to seemingly fire too many times?

Wanna see the remote event function

Let me try that and see what happens