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

What is wrong with this script that gives players rewards for having specific badges?

In my game I wanted to have players receive items for having a badge, I took a script that did this but with game passes instead of badges and changed it up so it would work with badges, the problem is, the script does not work, after fiddling with is for a while I decided that I should come here for help with the script. Any assistance would be greatly appreciated, here is the script:

id = 12312321 --Badge id
game.Players.PlayerAdded:connect(function(plr)
repeat wait() until plr.Character
if game:GetService("BadgeService"):PlayerHasBadge(plr, id) then
local tool = game.ServerStorage["Dream Bat"]
tool:clone().Parent = plr.Backpack
tool:clone().Parent = plr.StarterGear
end
end)

3 comments

0

^ ROBLOX announced that PlayerOwnsAsset will not work for badges anymore.

1 answer

I identified the problem very quickly.

You said PlayerHasBadge when the real method is UserHasBadge. Look here for more information. Try using this code:

id = 12312321 --Badge id
game.Players.PlayerAdded:connect(function(plr)
repeat wait() until plr.Character
if game:GetService("BadgeService"):UserHasBadge(plr, id) then
local tool = game.ServerStorage["Dream Bat"]
tool:clone().Parent = plr.Backpack
tool:clone().Parent = plr.StarterGear
end
end)

Please accept my answer if it worked. Thank you!

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