Problem with awarding badge

Hi guys! Can someone help me? I did a block when you touches it you get a badge, but the script doesn’t works, then my friend tried to fix and nothing changes, the print also doesn’t works.

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChildOfClass("Humanoid") then
		local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
		if plr and not game:GetService("BadgeService"):UserHasBadgeAsync(plr.UserId, 4243417087173871)then
			local IG = hit.Parent:FindFirstChild("IG")
			if IG and IG.Value == true then
				game:GetService("BadgeService"):AwardBadge(plr.UserId, 4243417087173871)
				print(plr.DisplayName .. " (@" .. plr.Name .. ") Awarded the badge Coconut!")

				local humanoid = plr.Character:FindFirstChild("Humanoid")
				if humanoid then
					humanoid.Sit = true
				end
			end
		end
	end
end)

Your script might not be working because:

  • The “IG” value doesn’t exist.

  • The script is a local script.

  • The badge id is incorrect.

  • This script is also a very dramatic and unnecessary way of doing this.

I checked and:

  • The “IG” value exists
  • The script are a normal script
  • The badge id its correct

I know it is, but IG are a value that means the player are with a food selected to avoid any bugs.

Where is your value located? Press F9 on your keyboard ingame and send a screenshot of the developer console if it’s erroring.

The value are lcoated in the player’s character, and when I touch the block, there’s no errors or prints in the developer console.

Have you even tested this in-game and not in studio? The Roblox player acts very different than a studio playtest.

So, in StarterCharacterScripts?

Yes, my friends and me tested various times.

Not exactly, But in player model in workspace.
(or just game.Players.LocalPlayer.Character)

  1. Make sure the value is in StarterCharacterScripts FIRST, so your script can find your value in the player.
  2. I just noticed that you didn’t wrap your UserHasBadgeAsync. If you don’t wrap it in pcall, your script will break and show no errors in the console.
local success, hasBadge = pcall(function()
	return BadgeService:UserHasBadgeAsync(plr.UserId, 4243417087173871)
end)

if success and not hasBadge then
	-- continue
end

  1. You could also do the same for the actual badge award section.

If you knew the player and had;

local badgeId = 4243417087173871
local badgeService = game:GetService(“BadgeService”)

Then all you would need is;

pcall(badgeService.AwardBadge, badgeService, player.UserId, badgeId) --one line

This would actually cover all cases you’re trying to do now…

That’s the easy part. Should add a debouce here as it will touch it 32 times at warp speed.
Also this should be a script in ServerScriptService not in the part. --too hackable

I know it looks odd, but it’s using the fact it may fail to its advantage, with only one call to badgeService. (Of course, make sure it works)

ServerScript
local touch = workspace:WaitForChild("Touchpart") --wherever this is

local badgeService = game:GetService("BadgeService")
local players = game:GetService("Players")
local badgeId = 4243417087173871
local db = {}

touch.Touched:Connect(function(hit)
	local player = players:GetPlayerFromCharacter(hit.Parent)
	if not player or db[player] then return end
	db[player] = true

	pcall(function()
		badgeService:AwardBadge(player.UserId, badgeId)
	end)

	task.wait(3)
	db[player] = nil
end)

--[[ testing
local success, err = pcall(function()
	badgeService:AwardBadge(player.UserId, badgeId)
end) print(success and "No error" or "Errored: "..err)
--]]
1 Like

Hi, have you considered that you already have the badge, and the first time testing this you accidently missed the badge notification? If this is very wrong and the studio playtest players badge database resets every run, excuse me, i dont have a lot of experience in BadgeService yet, i just wanted to reply just in case that is actually the solution. lol

1 Like

News: I just saw that the IG value wasn’t renamed lol

(Well thx everyone who tried to help)

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.