i wrote a script that turns a Gui on but something is wrong so can you tell me whats wrong my studio or the script
game:GetService("ReplicatedStorage").JanEv.OnServerEvent:Connect(function(player) wait(1) local Player=player game:GetService("Players")[Player.Name].PlayerGui.Jan.Enabled=true end)
Picture of the error:
https://i.gyazo.com/fe4eb2fb7b6f8aeed41bd9fc48f56bd8.png
PlayerGui:
https://i.gyazo.com/7da0773f5141bf951610865ab658791f.png
I think the problem is, you're putting Jan
into StarterGui
.
What I mean by this is that, StarterGui
doesn't replicate its descendants to the server.
So you're the only one that can see Jan
.
There are a couple of fixes you can do.
Fix 1:
Putting Jan
into PlayerGui
manually by a script.
You could let the server get Jan
, put it into the player's `PlayerGui', and then editing it.
That way the server and the client will be able to access it.
Fix 2:
Not letting the server enable the ScreenGui, but let the client do it
You might be wondering, "If I let the client change the properties, wouldn't it not replicate?"
That is correct. So why do we let the client do it? Because the client is the only one that's going to see the ScerenGui
.
In other words, No one else but you has to see your ScerenGui
, since it'll only show for you.
So how do we enable the ScerenGui
from the client? Simple, we don't even need the RemoteEvent
. We keep Jan
in StarterGui
, and then just simply:
-- LocalScript game:GetService("Players").LocalPlayer.PlayerGui.Jan.Enabled=true
Notes:
You should use :WaitForChild()
if you're immediately accessing an object, since it might not be loaded in yet.
It'll wait until the object you're waiting for is loaded in the game.
In this case, we just
-- LocalScript game:GetService("Players").LocalPlayer.PlayerGui:WaitForChild("Jan").Enabled=true
Basically, when you're editing a ScreenGui
, you only have to do it on the client since that client will be the only client that will see the ScerenGui
you're editing.
I'm sorry if anything I said wasn't explained well, I hope this helped you in any way.
If you have any questions I will try to answer them when I'm online.