Badge giver doesn't run in server

I’m trying to make a badge giver that gives a badge when you touch it and also give another if you have 3 other badges, and it works fine in studio. However, when I use it in normal game servers, it will not award any badge.

I’ve already tried debugging by using print receipts, as well as rewriting the whole script, but it still won’t work in game servers.

Code:

local b = game:GetService("BadgeService")
script.Parent.Touched:Connect(function(part)
	if part.Parent:FindFirstChild("Humanoid") then
		local player = game.Players:GetPlayerFromCharacter(part.Parent)
		if game:GetService("BadgeService"):UserHasBadgeAsync(player.UserId, 2143616126) == false then
			print("awardin badge")
			game:GetService("BadgeService"):AwardBadge(player.UserId, 2143616126)
		end
		if b:UserHasBadgeAsync(player.UserId, 2143616090) and b:UserHasBadgeAsync(player.UserId, 2143616106) and b:UserHasBadgeAsync(player.UserId, 2143616126) then
			print("wow all badges awardin badge")
			game:GetService("BadgeService"):AwardBadge(player.UserId, 2143616194)
		end
	end
end)

If anyone has a fix for this please reply below. Have a good day.

1 Like

Hi! I rewrote the script (because I was bored) . This SHOULD work, let me know if not.

local BadgeService = game:GetService("BadgeService")
local ID1,ID2,ID3,ID4 = 2143616126,2143616090,2143616106,2143616194
 db = false




script.Parent.Touched:Connect(function(hit)
	local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
	if db == false then
	if hit.Parent:FindFirstChild("Humanoid") then
		print("Actual Player")
		db = true
		
	if BadgeService:UserHasBadgeAsync(plr.UserId, ID1) then
		print(plr.Name .. " owns badge " .. ID1)
	else
		print(plr.Name .. " doesn't owns badge " .. ID1 .. ", awarding now")
		BadgeService:AwardBadge(plr.UserId, ID1)
	end
	
	if BadgeService:UserHasBadgeAsync(plr.UserId, ID2) and BadgeService:UserHasBadgeAsync(plr.UserId, ID3) and BadgeService:UserHasBadgeAsync(plr.UserId, ID1) then
		print(plr.Name .. " owns all badges, awarding badge " .. ID1)
		BadgeService:AwardBadge(plr.UserId, ID4)
	else
		print(plr.Name .. " doesn't own all badges.")
	end
		end
	else
		print("Debounce active!")
	end
	wait(2)
	db = false
end)

You don’t need to include “== false” for HasBadgeAsync, as if it is true you can do if true do.

Let me know if this works!

3 Likes

Thanks a lot! The script works now in both server and studio clients.

It was reporting that I didn’t have all badges at first when I thought I had them all (I tested my initial script on all givers and it gave all but last one) but I found I needed one more to get the last badge, not sure if it was a bug on my script or roblox’s end as some stuff happened with them today, but all stuff aside it finally worked and gave me the last badge. Again, thanks a bunch!

1 Like

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