Hello,
I want to make so when a player joins he will see the gui but i will see it too.
But my script is not working can someone please help?
Script:
local Hi = game:GetService("ReplicatedStorage"):WaitForChild("Hi") Hi.OnServerEvent:connect(function(plr) if plr.Name == "XxLavaStoneexX" then local Name = {"XxLavaStoneexX"} for i,v in pairs(game.Players:GetChildren()) do local gui = v.PlayerGui.ScreenGui.Frame.TextLabel:Clone() gui.Parent = plr.Name.PlayerGui.ScreenGui.Frame end end end)
LocalScript:
local Hi = game:GetService("ReplicatedStorage"):WaitForChild("Hi") Hi:FireServer()
Problem | Solution |
---|---|
You’re trying to modify the PlayerGui from the server, which doesn’t work. |
Fire a RemoteEvent to the client, modifying the PlayerGui locally. |
:connect() is deprecated |
Switch to :Connect() |
You’re trying to find the PlayerGui inside of the Name property |
Remove the .Name |
You’re using :GetChildren() on the Players service, which can error if something other than a Player object is inside Players |
Use :GetPlayers() to return ONLY Player objects |
-- LocalScript local plr = game:GetService("Players").LocalPlayer local plrGui = plr:WaitForChild"PlayerGui" -- Remember to define Hi Hi.OnClientEvent:Connect(function() local clone = plrGui.ScreenGui.Frame.TextLabel:Clone() clone.Parent = plrGui.ScreenGui.Frame end)
-- Server Script for _, v in pairs(game:GetService("Players"):GetPlayers()) do Hi:FireClient(v) end