Player can't get a badge when they touch a part no matter what I do

I want to give the player a badge when they touch a part.
I have tried so far 4 scripts and they don’t work. This is a huge problem now because I have to create a topic about this more than once in order to get any replies. I think this could be a bug or glitch but I’m not sure. I do not own the badge already, API access is enabled, badge is active, player can touch the part, the script is under the right part, but it won’t award the badge AT ALL.
I looked here many times but nothing worked. I am desperate to find a solution to this. I can’t understand why it won’t work. Somebody tested one of my scripts and it worked for them, so why won’t it work for me? I don’t want to go through the same 2 week process where I tried to figure out how to make cutscenes in one of my games. I just want to find out why this isn’t working an fix it. I wish I could get some in depth help on this.
I used these scripts:
Script 1:

local BadgeService = game:GetService("BadgeService")
local id = 2140926703
local badgegive = script.Parent

badgegive.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
		if not BadgeService:UserHasBadgeAsync(plr.UserId, id) then
			BadgeService:AwardBage(plr.UserId, id)
		end
	end
end)

Script 2:

local Players = game:GetService("Players")

local part = script.Parent
local badgeService = game:GetService("BadgeService")
local badge = 2140926703

part.Touched:Connect(function(hit)
	local player = Players:GetPlayerFromCharacter(hit.Parent)

	if not player then
		return
	end

	local hasBadge = badgeService:UserHasBadgeAsync(player.UserId, badge)
	if hasBadge then
		print( player.Name .. " owns this badge!")
	else
		badgeService:AwardBadge(player.UserId, badge)
	end
end)

Script 3:

local badgeservice = game:GetService("BadgeService")
local id = 2140926703 -- Your badge ID here


-- Part touched
script.Parent.Touched:Connect(function(hit)

	if hit.Parent:FindFirstChild("Humanoid")then

		local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
		badgeservice:AwardBadge(plr.UserId,id)
	end
end)

Script 4 (tested in my testing game):

local badgeService = game:GetService("BadgeService")
local id = 2140974247

script.Parent.Touched:Connect(function(hit)
	
	if hit.Parent:FindFirstChild("Humanoid") then
		
		local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
		badgeService:AwardBadge(plr.UserId, id)
	end
end)

I am worried that I could get warned or something for making so many topics like this but I am desperate for a solution. I have never been able to award badges on touch when I have tried in the past. I decided not to try and award a player a badge when they touch a part for a while because it would never work. Now I really want to have a badge for every stage/level the player completes in my game. I really hope somebody can give me a solution. I don’t want to make a bunch of topics but I need to in order to get replies. I want this nightmare to end. I want to figure out how to award a player a badge when they touch a part. I cannot continue working on the game easily without this.
All I ask is that, please, please, please, somebody out there, with knowledge on this, and somebody who knows exactly what might be wrong, somebody who can help me with this, gives me the solution to why this isn’t working.

did you check your inventory? Do you already have the badge? Sometimes roblox badge service can… break… It could work the best the few first times, but if you enable team test or something, it will break…

Any errors in output? Or anything similar? Have you checked that YOU already have the badge?

It shows I do not own the badge. I did enable team test and team editing or whatever it is, however I just hit play when I went to test it. I also made sure to publish the game and test it not in studio.

Yes… they might already have the badge. If they do, they should remove it from their inventory. They could also add a print() to make sure it is actually working.

No errors, I do not have the badge as far as I can tell.

You should add a print("Touched") just incase. Maybe the code isnt even running

I will check to see if it’s running.

Issues lies under the script it seems, is it a localscript or server script dare i say?
For security purposes:
Localscripts do not run in workspace.
Localscritps cannot award badges.

1 Like

Yes… you have to give badges using Server scripts. Local scripts cannot use badge service (from what i know of)

All the scripts are normal scripts, not local scripts.

The part is touched because it does print “touched”.

Sorry for saying this again… but maybe you should also print the players UserId. If it prints correctly, then you must have the badge already, or badge service just randomly broke.

Script 1 has a typo on line 9, you misspelled BadgeService:AwardBadge(). Fix:

local BadgeService = game:GetService("BadgeService")
local id = 2140926703
local badgegive = script.Parent

badgegive.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
		if not BadgeService:UserHasBadgeAsync(plr.UserId, id) then
			BadgeService:AwardBadge(plr.UserId, id)
		end
	end
end)

Wouldnt that not matter? They tried multiple scripts, right?

Like this?

print(plr.UserId)

I am testing script 3 right now.

local __BADGESERVICE = game:GetService("BadgeService")
local __PLAYERS = game:GetService("Players")
local __ID = 4574163471527 -- !! REPLACE

script.Parent.Touched:Connect(function(__PART)
	local __PLAYER = __PLAYERS:GetPlayerFromCharacter(__PART.Parent)
	if __PLAYER ~= nil then
		print("Here is your badge")
		__BADGESERVICE:AwardBadge(__PLAYER.UserId, __ID)
	end
end)
3 Likes

Yes… that should work, but you should also try weakroblox35’s script that just posted.

1 Like

Testing it right now so hopefully it works.