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

Why this Script don't work?

Asked by 10 years ago
local B1 = (IDhidden)

game.Players.PlayerAdded:connect(function(p)
    if game:GetService("BadgeService"):UserHasBadge(p.userId, B1) then
    game.Players.PlayerAdded.PlayerGui.SG.SF.B1.Check.Visible = true
    end
end)

Heres the StarterGui with the script (above) : http://imgur.com/xrJgkme

I own the badge, but the image doesn't turn visible when i play the game and i don't know why

0
Wait, was that image there before? M39a9am3R 3210 — 10y

1 answer

Log in to vote
2
Answered by
M39a9am3R 3210 Moderation Voter Community Moderator
10 years ago

You were trying to use a event to access a Player's Gui. You can not do that, you already have the variable for the new joined player though "p".

local B1 = (IDhidden)

game.Players.PlayerAdded:connect(function(p)
    if game:GetService("BadgeService"):UserHasBadge(p.userId, B1) then
         p:WaitForChild("PlayerGui").SG.SF.B1.Check.Visible = true --Just remove up to that event, and make sure you have some functions to protect the script from breaking, such as WaitForChild()
    end
end)

Alright, I just saw the image. So you know, PlayerAdded events WILL NOT work as intended in StarterGui or Backpack! They will not!

Here, I will fix up the code once more.

local B1 = (IDhidden)
    if game:GetService("BadgeService"):UserHasBadge(script.Parent.Parent.userId, B1) then
         script.Parent:WaitForChild("SG").SF.B1.Check.Visible = true --Since the script is in PlayerGui, just do this... and have some protection from the script breaking... WaitForChild().
    end
Ad

Answer this question