Roblox badge server not working

I am trying to make badges for my game that was made with my friend, but I made the game under my group.

Roblox thinks the badge is not mine or the script does not work
I’ve tried using tutorials on YouTube but they also don’t work.

Here’s the script that I used:

local BadgeService = game:GetService("BadgeService")
local Players = game:GetService("Players")
local BadgeGiver = script.Parent
local BadgeId = 2131647747 -- Replace 0 with your badge ID.

BadgeGiver.Touched:Connect(function (hit)
	local Player = Players:GetPlayerFromCharacter(hit.Parent)
	
	if BadgeService:UserHasBadgeAsync(Player.UserId, BadgeId) == false then
		BadgeService:AwardBadge(Player.UserId, BadgeId)
		return ("Given")
	else
		return ("Badge already exists.")
	end
end)
1 Like

Try this script, I modified it from BadgeService's documentation:
Make sure this script is in a Part or MeshPart. Not a model!

local BadgeService = game:GetService("BadgeService")
local Players = game:GetService("Players")

local BadgeGiver = script.Parent

local BADGE_ID = 0

local function awardBadge(player, badgeId)
	-- Fetch badge information
	local success, badgeInfo = pcall(function()
		return BadgeService:GetBadgeInfoAsync(badgeId)
	end)

	if success then
		-- Confirm that badge can be awarded
		if badgeInfo.IsEnabled then
			-- Award badge
			local awardSuccess, result = pcall(function()
				return BadgeService:AwardBadge(player.UserId, badgeId)
			end)

			if not awardSuccess then
				-- the AwardBadge function threw an error
				warn("Error while awarding badge:", result)
			elseif not result then
				-- the AwardBadge function did not award a badge
				warn("Failed to award badge.")
			end
		end
	else
		warn("Error while fetching badge info: " .. badgeInfo)
	end
end

local function DetectPlayer(hit)

	if hit and hit.Parent and hit.Parent:FindFirstChildOfClass("Humanoid") then

		return Players:GetPlayerFromCharacter(hit.Parent)

	end

end

local function onTouched(hit)
	local Player = DetectPlayer(hit)
	
	if Player then
		awardBadge(Player)
	end

end

BadgeGiver.Touched:Connect(onTouched)

try this script:

local BadgeService = game:GetService("BadgeService")
local BadgeGiver = script.Parent
local BadgeId = 2131647747 -- Replace 0 with your badge ID.

BadgeGiver.Touched:Connect(function (hit)
	local Player = game.Players:GetPlayerFromCharacter(hit.Parent)

	if not BadgeService:UserHasBadgeAsync(Player.	UserId, BadgeId) then
		BadgeService:AwardBadge(Player.UserId, BadgeId)
		return ("Given")
	else
		return ("Badge already exists.")
	end
end)

The badge must be under the game that your giving the badge in. If you’re sure it is, it must be the script that is failing.

It would error if the badge giver touches something that isn’t a player, but that doesn’t change the fact that is does touch a player eventually.

So make sure that the script is actually getting to that connection, and also that this is running on the server!

I have tried your script, and here’s the output: It did not work

Maybe you can add me to team create? I check maybe something else is wrong, it should work.
I’ve joined your group

Badges may not award correctly on Studio, try in a public game?

They did work for me. Not awarded but the reqard that I set when owning a badge worked. It’s possible to use badges in studio (even ones that come from other games) as long as you have it in your inventory.

Try removing the space between function and brackets.

function (hit)

Should be

function(hit)

Wouldn’t make any different to the code, but yes, that is a slight inconvience.

1 Like

I’m just warning them since if someone has OCD on this dev forum they might scream. (Joke btw)

1 Like

I did I saw that its giving me flashbacks to my code in a really big project im working on already.

1 Like

Sure I will add you to team create

Badges may not award correctly on Studio, try in a public game?

It is a public game

Try this script, I modified it from BadgeService 's documentation:
Make sure this script is in a Part or MeshPart . Not a model!

Screenshot 2023-01-19 at 8.41.56 AM

I tried using ChatGPT to make a script and here’s the result:

local part = script.Parent -- Assume the script is placed in the part

part.Touched:Connect(function(hit)
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
    if player then
        player:WaitForChild("Badges"):WaitForChild("NewBadge").Value = true
    end
end)

I know that this won’t work but anyone can modify it.

I’ve sent you a friend request, you will need to friend me so I can add you to team create

I accepted your friend request, please tell me when you add me.

Your badge is working now! Check it out in game!