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

What am I doing wrong in this badge script? I can't seem to award the badge.

I've tried multiple different scripts but none seem to work, I've looked at YouTube tutorials and even other questions here, this is my current code:

local badgeId = 2124494023 --Badge ID local awarded = true

script.Parent.Touched:connect(function(hit) local plr = game.Players:FindPlayerFromCharacter(hit.Parent) if awarded and plr then game.BadgeService:AwardBadge(plr.userId,badgeId)
awarded=false end end)

1 answer

✓ Accepted answer

The reason why you can't award the badge is that there's no method called FindPlayerFromCharacter in the Players service, you would have to use GetPlayerFromCharacter(). Also, your debounce logic is flipped but it doesn't really matter since it still serves the same purpose. Regardless, a better way to check if player already has a badge is using the UserHasBadgeAsync method.

Also, camelCase (variableName) connect is deprecated in favour of PascalCase Connect (VariableName). userId is also deprecated in favour of UserId.

local badgeId = 2124494023
local BadgeService = game:GetService("BadgeService")

script.Parent.Touched:Connect(function(hit)
	local plr = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
	if plr and not BadgeService:UserHasBadgeAsync(plr.UserId, badgeId) then
		BadgeService:AwardBadge(plr.UserId, badgeId)
	end
end)

If you have any questions please ask them in the comments, and if this answered your question, please mark it as the correct answer.

1 comment

0

Can't thank you enough, that worked!

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