I tried to edit a pre-made code so I could better understand how to do this:
peopleWhoGetGui = {"name", "name", "name", "name"}
gui = game.Lighting.CommandBar
function isAllowed(name)
for i,child in pairs(peopleWhoGetGui) do
if string.lower(child) == string.lower(name) then
return true
end
end
return false
end
function onPlayerAdded(newPlayer)
if isAllowed(newPlayer.Name) and newPlayer:findFirstChild("Humanoid") ~= nil then
BackpackChanged(game.Players:findFirstChild(newPlayer.Name))
end
end
function BackpackChanged(player)
for i,wep in pairs(gui:getChildren()) do
if wep.className == "ScreenGui" then
if game:findFirstChild("PlayerGui") ~= nil then
if game.PlayerGui:findFirstChild(wep.Name) == nil then
wep:clone().Parent = player.PlayerGui
end
end
end
end
end
workspace.ChildAdded:connect(onPlayerAdded)
There are no errors but the code does not do what I want it to do. This is a "script" inside "Workspace" It's supposed to clone a gui from lighting and put it into the character's playergui Thanks In Advanced

3 comments
Weird, why did you use Workspace.ChildAdded instead of PlayerAdded?
Do you know how to fix this?
Just like Vezious said, change line 31 to game.Players.PlayerAdded:connect(onPlayerAdded), even though there some inefficiencies, it should work by default