Trouble awarding player with badge

I’ve been testing this in studio and tried alternate version but I’m still not awarded the badge.

Here is the code:

--Checkpoint10 teleport script

local badgeId = 1854839377882498

local teleportPart = game.Workspace.Checkpoint10:FindFirstChild("SpawnPart")
local part = script.Parent

part.Touched:Connect(function(plr)
	local hrp = plr.Parent:FindFirstChild("HumanoidRootPart")
	if hrp then
		hrp.CFrame = teleportPart.CFrame + Vector3.new(0, 5, 0)
		local leaderstats = plr:FindFirstChild("leaderstats")
		local floors = leaderstats and leaderstats:FindFirstChild("Floors")
		local Player = game.Players:GetPlayerFromCharacter(plr.Parent)
		--give player badge
		local character = plr.Parent
		local humanoid = character:FindFirstChild("Humanoid")
		if humanoid then
			local player = game.Players:GetPlayerFromCharacter(character)
			if player then
				local badgeService = game:GetService("BadgeService")
				badgeService:AwardBadge(player.UserId, 1854839377882498)
			end
		end

		if floors and floors:IsA("ValueBase") then
			floors.Value = floors.Value + 1
		end
	end
end)

Thank you for reading!

1 Like

Sorry for the lack of comments, I’m still working on that.

I believe you’re getting the hrp wrong. It shouldnt be plr.Parent, i belive you should be using the hit parameter. Like this:

part.Touched:Connect(function(hit, plr)
local hrp = hit.Parent:FindFirshChild(“HumanoidRootPart”)
end)

Then use the plr parameter to award the badge.

badgeService:AwardBadge(plr.UserId, badgeId)

Hope this works

2 Likes

Yeah that does help but I’m still having problems with awarding the player with a badge. I’ve tried to see if this problem is continuous outside of this script by making a welcome badge and it still won’t award the player with the badge.

The badge is also enabled.

1 Like

You’re getting a BasePart from the touch event but not converting it to a Player for the badge call.
I think.. Not even sure how to say that.

local badgeId = 1854839377882498
local teleportPart = workspace.Checkpoint10:FindFirstChild("SpawnPart")
local part = script.Parent

part.Touched:Connect(function(hit)
	local char = hit.Parent
	local plr = game.Players:GetPlayerFromCharacter(char)
	if not plr then return end
	local hrp = char:FindFirstChild("HumanoidRootPart")
	if hrp then
		hrp.CFrame = teleportPart.CFrame + Vector3.new(0, 5, 0)
		local floors = plr:FindFirstChild("leaderstats") and plr.leaderstats:FindFirstChild("Floors")
		if floors and floors:IsA("ValueBase") then
			floors.Value += 1
		end
		game:GetService("BadgeService"):AwardBadge(plr.UserId, badgeId)
	end
end)

Basic check then Award

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

game.Players.PlayerAdded:Connect(function(player)
	local success, hasBadge = pcall(function()
		return BadgeService:UserHasBadgeAsync(player.UserId, badgeId)
	end)
	if success and not hasBadge then
		BadgeService:AwardBadge(player.UserId, badgeId)
	end
end)

Award or silent error (they own it or it isn’t going to work for a bit anyway :grinning_face_with_smiling_eyes:)

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

game.Players.PlayerAdded:Connect(function(player)
	pcall(function()
		BadgeService:AwardBadge(player.UserId, badgeId)
	end)
end)
1 Like

Make sure you have studio api enabled, cause that might interfere. Also sometimes studio js doesnt award badges so test it in the actual game outside of studio

Thanks for spotting that out (this might be my sign to get some sleep). This still doesn’t award the player with a badge. Is this a Roblox studio thing or am I doing something wrong(I’ve quadruple checked the Id of the badge along with having API services enabled).

I do have API enabled, I’ll make sure to test it outside of studio.

1 Like

Also make sure youre not using the asset id, but the badge id. I BELIEVE theres a difference.

Double check that tho, it might be for something else i was thinking of

I’ve used this function too. If errors, prints what error it was or where it happen.

local function AwardBadge(player, badge)
	local success, hasBadge = pcall(function()
		return BadgeService:UserHasBadgeAsync(player.UserId, badge)
	end)
	if not success then
		warn("Error while checking if player has badge!")
		return
	end

	if not hasBadge then
		local success, badgeInfo = pcall(function()
			return BadgeService:GetBadgeInfoAsync(badge)
		end)
		if success then
			if badgeInfo.IsEnabled then
				local awarded, errorMessage = pcall(function()
					BadgeService:AwardBadge(player.UserId, badge)
				end)
				if not awarded then
					warn("Error while awarding badge:", errorMessage)
				else
					print("Awarding badge")
				end
			end
		else
			warn("Error while fetching badge info!")
		end
	end
end

Maybe put prints to see if you reach certain parts of the scripts?

Swap

With

local model = plr:FindFirstAncestorOfClass("Model")
local hrp = model and model:FindFirstChild("HumanoidRootPart")

Also make sure that you are awarding the badge from the server side.

1 Like