Why is this function firing this event twice?

Hello, so I’ve been struggling with this one script for a while now and I can’t figure out why it fires “sellRemote” twice.

Code (Local Script):

player.selling:GetPropertyChangedSignal("Value"):Connect(function() --checks if the player is pressing down or not

	if player.selling.Value == true then --if player is holding down then
		print("player is selling")
		sellingBarOuter.Visible = true
		barTween:Play()
		barTween.Completed:Connect(function()
			if sellingBar.Size == UDim2.new(1, 0, 1, 0) then
				holdDownEnd:FireServer()
				sellRemote:FireServer()
				sellingBarOuter.Visible = false
				barTween:Cancel()
				sellingBar.Size = UDim2.new(0.05, 0, 1, 0)
			end
		end)
		player.Character:WaitForChild("Humanoid").Died:Connect(function()
			holdDownEnd:FireServer()
		end)
	else -- if player is no longer holding down then
		print("player is no longer selling")
		sellingBarOuter.Visible = false
		barTween:Cancel()
		sellingBar.Size = UDim2.new(0.05, 0, 1, 0)
	end
	
end)

A problem I’m also having is that when the player dies, “sellingBarOuter” will never become visible again no matter what. Everything else seems to work just fine.

The script is a mess and with a lot of listeners, events, etc. So I figured I’d send just the little part where the interested shenanigans occur, hopefully, it’s enough :smiley:

Instead of making sellingBarOuter visible when the player is added do it when the character is added through the CharacterAdded event (event which is fired every time a player’s character is added or in other words every time a character respawns). I’m not sure why that Remote is firing twice, is holdDownEnd only firing once?

sellingBarOuter is ‘visible = false’ by default, it should become visible only when selling, that’s why I’m confused as to why it’s not showing up when selling and after dying.
And YES! it is fired twice, one step closer to fixing it, but I’m not sure what that means x)

Are both remotes fired twice? holdDownEnd & sellRemote?

Yes, after holdDownEnd, sellRemote is fired and both get fired twice.

If they are then that means “barTween.Completed”, this event is firing twice.

local debounce = false
player.selling:GetPropertyChangedSignal("Value"):Connect(function() --checks if the player is pressing down or not
	if player.selling.Value == true then --if player is holding down then
		print("player is selling")
		sellingBarOuter.Visible = true
		barTween:Play()
		barTween.Completed:Connect(function()
			if debounce then
				debounce = false
				task.wait(5)
				return
			end
			debounce = true
			if sellingBar.Size == UDim2.new(1, 0, 1, 0) then
				holdDownEnd:FireServer()
				sellRemote:FireServer()
				sellingBarOuter.Visible = false
				barTween:Cancel()
				sellingBar.Size = UDim2.new(0.05, 0, 1, 0)
			end
		end)
		player.Character:WaitForChild("Humanoid").Died:Connect(function()
			holdDownEnd:FireServer()
		end)
	else -- if player is no longer holding down then
		print("player is no longer selling")
		sellingBarOuter.Visible = false
		barTween:Cancel()
		sellingBar.Size = UDim2.new(0.05, 0, 1, 0)
	end
end)

I’ve added a debounce to try and prevent that event from firing twice.

1 Like

Why tho? I don’t see anything that should make it fire twice even without a debounce, unless tweenService is currently broken?

Thanks :smiley: , adding a debounce fixes the main issue, any ideas on why the frame doesn’t become visible again when selling though?