Hi there! I'm having a problem with a remote event, attached to a local script. Here is a script that assigns GUI to the player (on server) , when their character is loaded:
GUI = game.ReplicatedStorage.GUI:GetChildren() if #player.PlayerGui:GetChildren() < 2 then for i = 1,#GUI do GUI[i]:Clone().Parent = player.PlayerGui end else game.ReplicatedStorage.LocalScript.RemoteEvent:FireClient(player) end
...this works fine. I've tested it multiple times and, accordingly, the script works. The problem is that the local script (that assigns GUI to the client) doesn't fire the event:
script.RemoteEvent.OnClientEvent:Connect(function(player) GUI = game.ReplicatedStorage.GUI:GetChildren() for i = 1,#GUI do GUI[i]:Clone().Parent = game.Players.LocalPlayer.PlayerGui end end)
Any help? I really appreciate it, thanks!
OnClientEvent
. This is because the server actually fires OnClientEvent
, so the client doesn't need any player parameter since clients can use LocalPlayer
. If an event passes the player by default, it's most likely a server-side only event! Though for FireClient
, the first argument is the Player
object the server will fire to. Also, LocalScript
s do not run in ReplicatedStorage
, they only run in PlayerGui
, Backpack
, PlayerScripts
, the Character
, and ReplicatedFirst
.local GUI = game.ReplicatedStorage.GUI:GetChildren() -- use local variables if #player.PlayerGui:GetChildren() < 2 then for i = 1,#GUI do GUI[i]:Clone().Parent = player.PlayerGui end else game.ReplicatedStorage.LocalScript.RemoteEvent:FireClient(player) end
-- Place in StarterPlayerScripts local rep = game:GetService("ReplicatedStorage") rep.RemoteEvent.OnClientEvent:Connect(function(player) local GUI = game.ReplicatedStorage.GUI:GetChildren() for i = 1,#GUI do GUI[i]:Clone().Parent = game.Players.LocalPlayer.PlayerGui end end)