Badge isn't awarding but script works fine

I’ve been trying to make this prompt award a badge when the player stops the input key. the “E” prints but the badge doesn’t award I have no clue why.

local badge = game:GetService("BadgeService")

local badid = 2142705857

	script.Parent.TriggerEnded:Connect(function(player)
		print("E")
		badge:AwardBadge(player.UserId, badid)
	end)

1 Like

Try this:

local badgeService = game:GetService("BadgeService")
local badgeId = 2142705857

script.Parent.TriggerEnded:Connect(function(player)
	print("E")
	local success,result = pcall(function()
		return badgeService:UserHasBadgeAsync(player.Userid,badgeId)
	end)
	if success then
		if not result then -- if player doesnt have the badge
			badgeService:AwardBadge(player.Userid,badgeId)
		end
	end
end)

it still did not work, what if i made a remote event and fire it upon being triggered

Does This Code Gives Out Any Error? If It Is, Follow The Error Instructions,
If Not Check If The Badge Id Is Correct Or Not, Check If Player Id Is Correct Or, Not, If Every thing is correct, Then You May Head To Roblox Documentation For Further Correction Of Code.
EDIT:

Is This Code Written On LocalScript, If It Is Then Write This Code On Script, The Scripts Written On Scripts Are Ran On Servers, And LocalScripts Are Ran On Clients, Make Sure Its Is On Server

there are no errors, the id is correct, I’ve looked at the documentation, that’s how I got what I had.

Maybe this is because you’re already having certain badge?
The code which is suppose to award you a badge may not run because you already have it.
Try checking your inventory and if you will find badge that is needed to be award to the player - remove it from your inventory and try executing your code again.

1 Like

I don’t have it I’ve checked several times to see if its giving me just no telling, mb I forgot to mention that initially

Alright, which script are you running the code then?

@TheGameDevPro26 mentioned, that you need to run the code on Server because if you would run it on Client, it would not work and it would be locally.

In case if you want to check the input locally and you want to give badge to the player on the server - you could use Remote Event, which allows you to communicate between client and server.

Make RemoteEvent and insert server script, make a function that gives player a badge and connect this function to AnyRemoteEvent.OnServerEvent:Connect(function(player, args)) so it would run on the client by AnyRemoteEvent:FireServer()

1 Like

Is your script a localscript or server? Client scripts I don’t think will be able to handle giving out badges.

Are you sure the badge id you’re using is correct? Is it linked to the game, or is it from a seperate game?

If the scripts working and the badge isn’t being awarded then that means there’s likely a problem on your part. Try to figure out what you’re doing wrong outside of the script and you should be fine.

2 Likes

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