How to clone screengui to playergui

before that, the server will clone the Zombie model from serverstorage to Workspace
which will make the Script ANIMATE active, and clone ScreenGui to Playergui

local player = game:GetService("Players")
local gui = script.Parent.GuiThing
gui.Parent = player.LocalPlayer.PlayerGui

but for some reason the script is not working?
image

you cant access LocalPlayer from the server

1 Like

like this guy says, if you do player.LocalPlayer on the server. It’s going to look for a object or player named “LocalPlayer”. When will the server clone the zombie? does it get added during a player interaction?

LocalPlayer does not exist for the perspective of the server. The server handles every player in the server, not just one player, so LocalPlayer can not be a specific player.

What you can do is whenever you need to perform this task, you can make the client fire a RemoteEvent which will signal the server to perform this action. Since the Player instance of the user who fired it will be always the first argument passed into the callback function of the .OnServerEvent signal, you can shove the ScreenGui into that player’s PlayerGui.

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player)
	-- the player instance here will be equivalent to the localplayer, you can then access player.PlayerGui from here
end)
1 Like

Accessing local player from the server is not possible since the server takes into account all the players in the game, not a singular one like a local script. To clone the screen gui into their player gui, you want to use a remote event, an instance which functions like an event that allows for the client and server to communicate. This is the format, (put a remote event called CloneGui in rep storage)

local gui = script.Parent.GuiThing
for I,player in pairs(game.Players:GetPlayers()) do
   game.ReplicatedStorage.CloneGui:FireClient(player,gui)
end

Then in the client… (local script in startergui)

local player = game.Players.LocalPlayer
game.ReplicatedStorage.CloneGui.OnClientEvent:Connect(function(gui)
   gui.Parent = player.PlayerGui
end