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

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

Asked by 7 years ago

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)

0
^ ROBLOX announced that PlayerOwnsAsset will not work for badges anymore. Thundermaker300 554 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago

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!

Ad

Answer this question