Im trying to fire a remote event from a module script that is located in server storage, the local script recieves the event and applies lighting settings. For some reason sometimes the remote event doesnt work and stops recieving any data.
I have tried putting the local script in replicated first, I disabled reset on spawn in gui but it doesnt seem to help
Heres the code and some images
local Lighting = game:GetService("Lighting")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvents = ReplicatedStorage:WaitForChild("RemoteEvents")
local function ApplyLighting(LightingFolder:Folder)
local DefaultValuesFolder = LightingFolder:FindFirstChild("DefaultValues")
local EffectsFolder = LightingFolder:FindFirstChild("Effects")
for Index, Part in Lighting:GetDescendants() do
local Tags = Part:GetTags()
if table.find(Tags, "Temporary") then
Part:Destroy()
end
end
for Index, LightingValue in DefaultValuesFolder:GetChildren() do
Lighting[LightingValue.Name] = LightingValue.Value
end
for Index, Effect:ColorCorrectionEffect in EffectsFolder:GetChildren() do
local EffectClone = Effect:Clone()
EffectClone:AddTag("Temporary")
EffectClone.Parent = Lighting
end
end
ApplyLighting(workspace.LobbyFolder.Lighting)
RemoteEvents:WaitForChild("ApplyLighting").OnClientEvent:Connect(function(Folder:Folder)
print("ApplyLighting")
ApplyLighting(Folder)
end)
Your local script may not be connecting to the remote event until after it’s been fired by the server.
Where/when is the remote event being fired from the server?
Like the server script that must be requiring the module script you fire it from and calling whatever function fires it.
You can check by adding prints right before the event is fired from the server and prints right before the RemoteEvents:WaitForChild("ApplyLighting").OnClientEvent:Connect in your local script.
Hmm ,and where is the print in the localscript? Is it right before you connect to the Remote Event? If it’s elsewhere in the script it’s possible a :WaitForChild is still causing the :Connect to run after the server script has already fired the event.
Everything you’re seeing, especially the randomness, is typical of race conditions where the scripts load/run in different orders.
You can try a wait before firing from the server script, or you can use like a RemoteFunction from the client to fetch the lighting folder from the server.
So if you’re saying it’s not the difference/order of the client first connecting to the remote event vs. when it’s fired could it be how it’s being fired?
Are you doing :FireAllClients or :FireClient on a specific Player?