Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why the is not cloning the Gui into PlayerGui?

Asked by 5 years ago

Here is the code:

local gui = script.ScreenGui

game:GetService("Players").PlayerAdded:Connect(function(player) if player == "SwordChin" then for i,v in pairs(game.Players:GetChildren()) do gui:Clone().Parent = v.PlayerGui end end end)

1
Player is a player object, not a string theking48989987 2147 — 5y
0
you can check if the player's name is "SwordChin" instead if the player is "SwordChin" theking48989987 2147 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

Try something like this:

local gui = script.ScreenGui
local players = game.Players

local function onPlayerAdded(player) --Separate functions for clarity
    if player.UserId == 640603301 then  --Use the UserId instead of names, as that can never be changed
        local playerList = players:GetChildren()
        for count,player in ipairs(playerList) do  --Use ipairs(). Also, properly naming variables is important
            gui:Clone().Parent = player.PlayerGui  
        end  
    end  
end

players.PlayerAdded:Connect(onPlayerAdded)

This should work. Hope I helped :D

0
Thank you! Was just to change the player by player.Name,but thank you SwordChin 2 — 5y
0
No problem! I'm glad I helped. Also, can you Accept this answer? RiskoZoSlovenska 378 — 5y
0
By all means SwordChin 2 — 5y
Ad

Answer this question