local replicatedstorage = game:GetService("ReplicatedStorage") local badgeservice = game:GetService("BadgeService") local badges = replicatedstorage:WaitForChild("Badges") local alphaid = badges:WaitForChild("Alpha") game.Players.PlayerAdded:connect(function(player) if badgeservice:UserHasBadge(player.userId, alphaid.Value) then print("1") player.PlayerItems.Alpha.Value = true end print("Done") end)
I have the badge, but when I join it doesn't work. The only other thing in the script is just created an Instance of PlayerItems and the Alpha, but it prints "Done" so it should work, it's just not picking up that I have the badge. Should I add a wait or something?. I have checked the wiki and it should work.
alphaid is an IntValue
Please help!
You're using WaitForChild before you're listening for PlayerAdded, so the player is joining before the objects have loaded into the game. Here's how you can fix it.
local replicatedstorage = game:GetService("ReplicatedStorage") local badgeservice = game:GetService("BadgeService") local badges = replicatedstorage:WaitForChild("Badges") local alphaid = badges:WaitForChild("Alpha") local function badges(player) if badgeservice:UserHasBadge(player.userId, alphaid.Value) then print("1") player.PlayerItems.Alpha.Value = true end print("Done") end for i, v in pairs(game:GetService("Players"):GetPlayers()) do coroutine.resume(coroutine.create(badges),v) end game:GetService("Players").PlayerAdded:connect(badges)