My friend has an issue with a BadgeService script. When a player joins the game, if he owns a Badge, the GUI frame will be Visible.
local badgeId = 2124674232
local player = game.Players.LocalPlayer
local BadgeService = require(game.ServerScriptService:WaitForChild(“BadgeService”))
local player = game.Players.PlayerAdded:Connect(function(badgeId)
local haloGui = script.Parent:WaitForChild(“HaloGui”)
local haloFrame = haloGui.MainFrame.ScrollingFrame:WaitForChild(“OrangeHalo”)
local locked = haloFrame:WaitForChild(“Locked”)
local equip = haloFrame:WaitForChild(“Equip”)
haloFrame.Visible = false
if BadgeService then
haloFrame.Visible = true
locked.Visible = false
end
if not BadgeService then
locked.Visible = true
haloFrame.Visible = true
equip.Visible = false
end
I can’t really detect the issue in the script.
Thanks for your help!
You’re just checking to see if the BadgeService exists or not…? You have to use UserHasBadgeAsync if you wanna check if a user has a badge or not
If this line is on a server script, you can’t define it like that. That only works for LocalScripts, cause the Server can’t even find where the “Local Player” is.
Why are you trying to define it as a variable? You just need to make it a function, plus the “badgeid” argument is not the badgeid. The first parameter is the Player that joined.
There’s a couple issues that I really see, but it should be easily fixed though:
local badgeId = 2124674232
local BadgeService = require(game.ServerScriptService:WaitForChild(“BadgeService”))
game.Players.PlayerAdded:Connect(function(Player)
local haloGui = script.Parent:WaitForChild(“HaloGui”)
local haloFrame = haloGui.MainFrame.ScrollingFrame:WaitForChild(“OrangeHalo”)
local locked = haloFrame:WaitForChild(“Locked”)
local equip = haloFrame:WaitForChild(“Equip”)
haloFrame.Visible = false
if BadgeService:UserHasBadgeAsync(Player.UserId, badgeid) then
haloFrame.Visible = true
locked.Visible = false
end
if not BadgeService:UserHasBadgeAsync(Player.UserId, badgeid) then
locked.Visible = true
haloFrame.Visible = true
equip.Visible = false
end