Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why this Script don't work?

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

2 comments

0

Wait, was that image there before?

1 answer

✓ Accepted answer

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

This discussion is preserved as it was. New answers, comments, and votes are closed.