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)
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
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.
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()
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.