So what I'm trying to do is make a ticket giver using a TextButton and a Remove Event. When the TextButton is clicked, the player that had its name inserted into a String Value will get the ticket. Everything works fine, but when a player would click the TextButton, the player would usually get more than 1 ticket. The more they do it, the more tickets they would get.
Local Script -
local TicketExchange = game.ReplicatedStorage.TicketExchange --Remote Event script.Parent.MouseButton1Click:Connect(function() local Name = script.Parent.Parent.Parent.PlayerName.Value --Player's Name from a String Value TicketExchange:FireServer(tostring(Name)) end)
Script -
local TicketExchange = game.ReplicatedStorage.TicketExchange local Ticket = game.ReplicatedStorage.Ticket --The Tool TicketExchange.OnServerEvent:Connect(function(Player, Name) local TicketClone = Ticket:Clone() --Cloning Ticket TicketClone.Parent = game.Players[Name].Backpack --Giving the player the Ticket end)
You most likely need to add a debounce system. What is happening right now is when a player clicks the text button, the script recognizes several clicks because the mouse is holding down, activating the remote event several times before the player lifts their mouse. The best way to fix this is to add a debounce system. A debounce system makes sure that when someone clicks a button or touches a pad, multiple signals are not sent. You can alter your script to add a debounce system by adding this into your local script:
local debounce = true -- states whether or not the event can be activated again script.Parent.MouseButton1Click:Connect(function() if debounce = true then -- if the event can be activated again debounce = false -- sets it so the event can’t be activated again RemoteEvent:FireServer() wait(0.2) -- this is the time in between when a player can activate the event again. You can change it to whatever you want. I forgot what I use so I would look up good debounce times on the internet debounce = true -- the event can be activated again end end)
I hope this helps you, I’m not the best explainer so if you still don’t understand it I would look up the wiki reference of it, it explains it well. Best of luck to you!