In my game, when players are put into teams they are given a clone of a script that is initially disabled but is re-enabled when given. This script listens for remote events that basically display a GUI when their team wins or loses, and displays a game result GUI that covers the screen.
When one team wins, events are fired like this from a server script:
Ghostvictoryevent:FireAllClients() --Any player on the ghosts team has a script inside them that listens for this, when it is activated it displays a gui that says "Mission Success" and then displays a game result screen a few seconds after. Only players that were put on the Ghost team have that script inside of them, and will be affected by this event.
SFfailureevent:FireAllClients() -- Same thing, but for the other team.
Any player that is in the current round will have their team script inside of them for the remote events to affect them, this announces that the game is over, mid-game announcements, and displays the match results.
When a player is left to spectate, meaning they sit out while the others play a round, the spectator is not given a script so any remote event fired from the server to display the winner and game results will that affect the spectator.
The issue is when the spectator plays the next round and is given the script, it seems that all the remote events that were called from last round happen at once and only towards that player.
Is this because even though the script is disabled, it still listens for remote events? And when it is re-enabled it does whatever the remote event said to do if the client that is given the script was not around to be affected by the event?
It seems like that might be what is happening but it doesn't make sense that a disabled script would still listen for remote events. If this is the cause, is there a way to keep it from doing that? If its not the cause then I'll have to figure out what really is the cause.
Thank you in advance!
Here is one of the scripts that is cloned, parented to the player, and re-enabled.
local Players = game:GetService("Players") local ReplicatedStorage = game:GetService("ReplicatedStorage") local Player = Players.LocalPlayer local GhostVictory = ReplicatedStorage:WaitForChild("GhostVictoryEvent") local RoundTime = ReplicatedStorage:WaitForChild("RoundTimeEvent") local GhostFailure = ReplicatedStorage:WaitForChild("GhostFailureEvent") local PlantedA = ReplicatedStorage:WaitForChild("APlantedEvent") local PlantedB = ReplicatedStorage:WaitForChild("BPlantedEvent") local GhostCount = ReplicatedStorage:WaitForChild("GhostCountEvent") local SFCount = ReplicatedStorage:WaitForChild("SFCountEvent") local BombDroppedAlert = ReplicatedStorage:WaitForChild("BombDropAlertEvent") local GameEnd = ReplicatedStorage:WaitForChild("GameEndEvent") local RoundStart = ReplicatedStorage:WaitForChild("RoundStartEvent") local StarterGui = game:GetService('StarterGui') --==GameGuis==-- local PlayerService = game:GetService('Players') local PlayerGui = PlayerService.LocalPlayer:WaitForChild('PlayerGui') local GameGuis = PlayerGui:WaitForChild('GameMessages') local OverlayGUI = PlayerGui:WaitForChild('GhostOverHeadGui') local MainMenu = PlayerGui:WaitForChild('MainMenu') OverlayGUI.Enabled = true local function onRoundStart() MainMenu.Enabled = false StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.All, true) --OverlayGUI.RoundStartGhost.Visible = true wait(3) --OverlayGUI.RoundStartGhost.Visible = false end local function SFCountUpdate(SF) OverlayGUI.SFAlive.Text = SF end local function GhostCountUpdate(Ghosts) OverlayGUI.GhostsAlive.Text = Ghosts end local function RoundTimeUpdate(timer) OverlayGUI.Time.Text = timer end local function onVictory() print("GWIN") GameGuis.MissionSuccess.Visible = true wait(3) PlayerGui.GameResult.Enabled = true GameEnd:FireServer() end local function onFailure() print("GFAIL") GameGuis.MissionFailed.Visible = true wait(3) PlayerGui.GameResult.Enabled = true GameEnd:FireServer() end local function onPlantedA() GameGuis.BombPlantedA.Visible = true wait(3) GameGuis.BombPlantedA.Visible = false end local function onPlantedB() GameGuis.BombPlantedB.Visible = true wait(3) GameGuis.BombPlantedB.Visible = false end local function onBombDrop() GameGuis.BombHasBeenDropped.Visible = true wait(3) GameGuis.BombHasBeenDropped.Visible = false end GhostVictory.OnClientEvent:Connect(onVictory) RoundTime.OnClientEvent:Connect(RoundTimeUpdate) GhostFailure.OnClientEvent:Connect(onFailure) PlantedA.OnClientEvent:Connect(onPlantedA) PlantedB.OnClientEvent:Connect(onPlantedB) GhostCount.OnClientEvent:Connect(GhostCountUpdate) SFCount.OnClientEvent:Connect(SFCountUpdate) BombDroppedAlert.OnClientEvent:Connect(onBombDrop) RoundStart.OnClientEvent:Connect(onRoundStart)
A disabled script does not listen for remote events or remote functions, which means it also wont fire these when the script is re-enabled UNLESS if something calls for it WHEN it is enabled.