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

I have no idea what is going wrong with this script?

Asked by 8 years ago
Owner = "mustardfoot"
local Players = game:GetService("Players")

function onPlayerAdded(player)
if player.Name == Owner then
    do game.ServerStorage.OwnerGui:Clone().Parent = game.StarterGui
    wait(4)
    game.StarterGui.OwnerGui:Destroy()
end
end
end

I see no problem in output, but no matter what I do the gui won't show.

0
Try cloning the gui in PlayerGui instead of StarterGui Demon_ster 67 — 8y
0
How do I clone it into everyone's PlayerGui? mustardfoot 90 — 8y

1 answer

Log in to vote
1
Answered by
BlackJPI 2658 Snack Break Moderation Voter Community Moderator
8 years ago

What is StarterGui?

A problem I see a lot of people first starting out programming on Roblox have is understanding what exactly the services that Roblox gives you actually do, StarterGui being one of these services.

StarterGui is a Class that the Roblox team created so that you could very easily make every player that joins the game start with the tool in their backpack. However, developers often want to control when the player can obtain and use these tools.

Some developers get caught up in the StarterGui Class trying to use it like how you used it in your script, but the problem is it's just wrong. What if a user joins while the GUI is still in the StarterGui? Then he could get the GUI that he isn't suppose to have!

The Solution

Using the PlayerAdded event like you did in your script, we can directly place the GUI we want the player to receive into their PlayerGui:

local Owner = "mustardfoot"
local GUI = game.ServerStorage.OwnerGui

game.Players.PlayerAdded:connect(function(player)
    player.CharacterAdded:connect(function(character)
        if player.Name == Owner then
            GUI:Clone().Parent = player.PlayerGui
        end
    end)
end) 

I also added in the CharacterAdded event so that the player gets the GUI again if they die, however there are other ways to get around this problem.

Ad

Answer this question