The leaderstats value that always increases every time I jump from the seat

So I’m making a system where if a player sits on a seat, then that player can click on the screen and earn money.

But why is it that every time I jump “Get out of Seat” and then I sit down again, the value will increase by 2 times, which previously only increased +1 if I left clicked, but when I jump and sit down again the value becomes +2, and this it happens again and again until i got a really huge value.

This is my code, if there is an mistakes please tell me:

– LocalScript

if isSeat then
		if seat.Name == "WorkSeat" then
			deb = true
			print("You're Working!")
			mouse.Button1Down:Connect(function()
				if deb == true then
					remote:FireServer()
				end
			end)
		else
			deb = false
		end
	end
	
	if not isSeat then
		deb = false
	end

– ServerScript

local RS = game:GetService("ReplicatedStorage")
local remote = RS:WaitForChild("RemoteEvent")

remote.OnServerEvent:Connect(function(plr)
	plr.leaderstats.Coins.Value += script.Value.Value
end)

that it because you didn’t disconnect fire remote event (it will bind every time you sit) try change to this

if isSeat then
		if seat.Name == "WorkSeat" then
			deb = true
			print("You're Working!")
            local Connection
			Connection = mouse.Button1Down:Connect(function()
				if deb == true then
				    remote:FireServer()
                    Connection:Disconnect()
				end
			end)
		else
			deb = false
		end
	end
	
	if not isSeat then
		deb = false
	end

Thanks, actually the code you provided didn’t work but I used the Connection you provided and it worked

1 Like