Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why are there multiple outputs from single command?

Basically, i want a button to be pressed, then through that button, a remote event is fired. The problem is that it sends the remote event many times even though i only pressed the button once. I have tried using debounce but it doesn't work

here is the code:

b1button.MouseButton1Down:Connect(function()
			if Cash >= DC1price then
				if buttonpressed == false then
					buttonpressed = true
					Cash = Cash - DC1price
					print("item bought")
					confirm.Visible = false
					item1:FireServer(1)
					
					buttonpressed = false
				end
				
				
			end
		end)

this is with debounce.

Also there is a strange pattern in the output, first it sends one remote event, then when i press it again it sends 2, then 3, then 4, ect So the outputt shows:

item bought (*1)

then next time the number adds:

item bought(*3)

and again

item bought(*6)

Anyone see any problem?

Thanks :)

edit: Someone asked for the server script, I don't think it has anything to do with it, since it is just recieving the remote event. The problem is that the item bought output from the "print item bought" is being printed several times every time i press the button, and the remote event being fired is just the result. but here is the server script anyways:


item1.OnServerEvent:Connect(function(Player, amount)
	Player.itemcounter.DC1.Value = Player.itemcounter.DC1.Value + amount
end)

3 comments

0

can you show the server script too?

0

you only showed me the local script. It could be the server script's problem too

0

i edited it

1 answer

Well, that is your problem.

Client-sided changes do not replicate to the server, so the client is constantly reading it as being greater than or equal to the value of DC1price. This means that when you click the button, you should immediately fire the signal to the server in order to handle transactions. The debounce is ineffective for this exact reason.

1 comment

0

So should i fire the event right after the if statement?

This discussion is preserved as it was. New answers, comments, and votes are closed.