#Problem with firing events multiple times

1 messages · Page 1 of 1 (latest)

autumn vigil
#

So I have a cutscene script for my game, and it plays cutscenes for all players.

When in that script reaches the point where the cutscene has to fire a server event, it does it normally. If there was 1 player in the server then it wouldnt be a problem. But because each player plays the same cutscene on their client, when they reach the point for the event to fire, then multiple clients fire the same event.

So let's say in the cutscene I want a door to open, or an npc to walk, then multiple clients will fire to do said things and weird issues will occur.

i haven't thought of a solution to this yet and the ideas that come to mind are not really preferable

thick iron
#

you need a debounce.
on the serverside, you should use a variable to track whether the cutscene is not already playing. if any player fires that event, that variable should be set to true, so that on next calls, when you check if the debounce is active, you just return without doing anything.

#

something like:

local debounce = false
event.OnServerEvent:Connect(function(plr)
  if not debounce then
    --play your cutscene
  end
end)
autumn vigil
#

That could work, but i would need to add a cooldown;

the cutscene plays on the client, [Cutscene i mean, camera movement, dialogue, effects ect] the only thing that is serversided are events like "open gate", or "npc goes there", ect

if i were to use the debounce approach, im afraid what if another scene triggers fast enough so the next time i need to use said event, it's unavailable? that's what i thought when the idea first came to mind.

my worries might be unfounded though, i dont know

#

maybe im overcomplicating it

thick iron
#

you wouldn't use one debounce across all cutscenes - you would create one for each.
for cutscene1 you have debounce1 and so on and so forth.

with that (assuming you have a way of interrupting previous dialogue) if a new scene needs to be triggered over a playing one, it will just play because it's a different scene.

autumn vigil
#

oh yea that's smart

#

idk if that's what you're saying, but i can pass a debounce id for every server event maybe

#

yea ill probably do that

#

thank you

thick iron
#

no problem

#

glad i could help.

#

(by the way yes, that's a nifty way of doing it)