Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Why does my remote event fire more than once?

Asked by
l1u2i3 52
4 years ago

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)
0
real tired to look into it, but look for where you are creating your events. you are most likely creating an event somewhere every time the player clicks the button royaltoe 5144 — 4y
0
most likely you have multiple mouseclick funcitons royaltoe 5144 — 4y
0
Where is the gui stored? sahadeed 87 — 4y
0
make sure to add in a debounce on the mousebutton1click event. ForeverBrown 356 — 4y

1 answer

Log in to vote
0
Answered by
Sulu710 142
4 years ago

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!

0
I thought this answer helped, but it sadly didn't. For some reason the amount of ticket depends on the amount of players that are in the game. 2 players = 2 tickets, 1 player = 1 ticket. Do you know why it does this? l1u2i3 52 — 4y
0
I'm sorry, I don't know what's causing that. My script example wasn't what you should put in your game, I shortened it to easier explain debounce. You would still need to add your "local Name = script.Parent.Parent.Parent.PlayerName.Value" and "TicketExchange:FireServer(tostring(Name))end)" instead of my simple "RemoteEvent:FireServer()". Sulu710 142 — 4y
0
If you did this and you included your full server and local scripts in your question, then I am unsure of the cause, I'm sorry. Sulu710 142 — 4y
Ad

Answer this question