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:
1 | GUI = game.ReplicatedStorage.GUI:GetChildren() |
2 | if #player.PlayerGui:GetChildren() < 2 then |
3 | for i = 1 ,#GUI do |
4 | GUI [ i ] :Clone().Parent = player.PlayerGui |
5 | end |
6 | else |
7 | game.ReplicatedStorage.LocalScript.RemoteEvent:FireClient(player) |
8 | 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:
1 | script.RemoteEvent.OnClientEvent:Connect( function (player) |
2 | GUI = game.ReplicatedStorage.GUI:GetChildren() |
3 | for i = 1 ,#GUI do |
4 | GUI [ i ] :Clone().Parent = game.Players.LocalPlayer.PlayerGui |
5 | end |
6 | 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
.1 | local GUI = game.ReplicatedStorage.GUI:GetChildren() -- use local variables |
2 | if #player.PlayerGui:GetChildren() < 2 then |
3 | for i = 1 ,#GUI do |
4 | GUI [ i ] :Clone().Parent = player.PlayerGui |
5 | end |
6 | else |
7 | game.ReplicatedStorage.LocalScript.RemoteEvent:FireClient(player) |
8 | end |
1 | -- Place in StarterPlayerScripts |
2 | local rep = game:GetService( "ReplicatedStorage" ) |
3 |
4 | rep.RemoteEvent.OnClientEvent:Connect( function (player) |
5 | local GUI = game.ReplicatedStorage.GUI:GetChildren() |
6 | for i = 1 ,#GUI do |
7 | GUI [ i ] :Clone().Parent = game.Players.LocalPlayer.PlayerGui |
8 | end |
9 | end ) |