Badge not awarding when supposed to

So the output in Roblox Studio says it’s being awarded but when I go into the Roblox game it isn’t.
The badges are active as well.
Here’s my code

local Player = game:GetService("Players").LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local Players = game:GetService("Players")
local PlayerModule = require(game.Players.LocalPlayer.PlayerScripts:WaitForChild("PlayerModule"))
local Controls = PlayerModule:GetControls()
local Badge_Service = game:GetService("BadgeService")
local Players = game:GetService("Players")
local BadgeID = 2125784344
local BadgeID1 = 2125784379

local Prompt = game.Workspace.WaterCanxiety.ProximityPrompt
local screengui = game.Players.LocalPlayer.PlayerGui.ScreenGui
local PGUI = game.Players.LocalPlayer.PlayerGui.PGUI
local Text = game.Players.LocalPlayer.PlayerGui.PGUI.Text
local No = game.Players.LocalPlayer.PlayerGui.PGUI.No
local Yes = game.Players.LocalPlayer.PlayerGui.PGUI.Yes
local NResponse = game.Players.LocalPlayer.PlayerGui.PGUI.NResponse
local YResponse = game.Players.LocalPlayer.PlayerGui.PGUI.YResponse
local Frame = game.Players.LocalPlayer.PlayerGui.PGUI.Frame
local scammed = game.Players.LocalPlayer.PlayerGui.PGUI.Frame.scammed
local no = game.Players.LocalPlayer.PlayerGui.PGUI.Frame.no



Prompt.Triggered:Connect(function()
	Prompt.Enabled = false
	Controls:Enable(false)
	No.Visible = true
	Yes.Visible = true
	Text.Visible = true
end)

No.MouseButton1Click:Connect(function()
	No.Visible = false
	Yes.Visible = false
	Text.Visible = false
	NResponse.Visible = true
	wait(2)
	Frame.Visible = true
	no.Visible = true
	wait(2)
	if not Badge_Service:UserHasBadgeAsync(Player.UserId,BadgeID1) then
		Badge_Service:AwardBadge(Player.UserId,BadgeID1)
	wait(2)
	print(Player, "ending n")
	Player:Kick("Ending: no")
end)

Yes.MouseButton1Click:Connect(function()
	No.Visible = false
	Yes.Visible = false
	Text.Visible = false
	YResponse.Visible = true
	wait(2)
	Frame.Visible = true
	scammed.Visible = true
	wait(2)
	if not Badge_Service:UserHasBadgeAsync(Player.UserId,BadgeID) then
		Badge_Service:AwardBadge(Player.UserId,BadgeID)
	wait(2)
	print(Player, "ending s")
	Player:Kick("Ending: scammed")
	end
	end)

I’m pretty new to BadgeService as well so its probably a small mistake.

2 Likes

Badges can only be awarded from a ServerSide Script. You cant grant players badges from the client / local script.

2 Likes

How would I award it then in a different script?

Use a remote event to fire from the client to the server with the badge ID present in the params then award it on the server

I honestly have no idea how I would do that

Here is a quick briefing on remoteEvents.

First, put a RemoteEvent in ReplicatedStorage. In this example I kept it the default name of RemoteEvent.

Whenever you’re ready to award the badge, do the following in your client script:

game.ReplicatedStorage.RemoteEvent:FireServer(2125784344)

At this point, you’ve now sent information to the server via that RemoteEvent. The server will see the player who sent that RemoteEvent as well as 2125784344. In this case, it’s the badgeId. At this point you’d create a ServerScript in ServerScriptService and try the following:

local BS = game:GetService("BadgeService")

local function awardBadge(plr, id)
-- if you want to add a check here to see if the player owns the badge you can, although if the player doesn't own the badge it won't reward the badge regardless
   BS:AwardBadge(plr.UserId, id) -- might be useful to wrap this in a pcall by the way, but you haven't done so in your original script so i've refrained from doing so here.

end
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(awardBadge)

That’s the basics of it. Obviously I’d recommend adding a pcall to that like stated in the script. I’d also probably recommend securing the remote somehow to make sure exploiters don’t just fire the event. Also to ensure the player gets kicked, you could always add the Player:Kick() on the ServerSide and pass the message you’d like to from the client as well. That would prevent people who are just firing the remote itself from not getting kicked.

1 Like

Sorry I’m on phone rn but what he meant is that you can make a remote event in Repllicated Storage and use it to communicate through client and server. Then, on the server side you set it up so when the remote event is fired, give the player the badge. If there are requirements for badges like levels or somethings, make sure to check it from the server. Use a pcall function to handle errors. Sorry I am on a phone right now I can explain it a bit more on my computer and give code sample later.

Okay this actually makes sense and it did work, I’ll try experimenting with this to further understand it, thank you for clarifying it for me!

1 Like