Badge not working

So basically my script to give a badge isnt working
script:

local IDToAward = 2128438468 --Replace this with your BadgeID
local BadgeService = game:GetService("BadgeService")
local Players = game:GetService("Players")


local tool = script.Parent
function onActivation()
	BadgeService:AwardBadge(Players.LocalPlayer.UserId, IDToAward)
	wait (1)
	Players.LocalPlayer:Kick("You got the Pink Sauce!!!")
end

tool.Activated:Connect(onActivation)
--2128438468

i dont know what i did wrong-
edit: i tested it in actual roblox, not studio.

You can’t award badges on the client. You’re going to have to do this on a Server Script.

You cant use “Local Player” in a server script. Find another way of referencing the player

how do i do that??
im stupid and dont know what a server script is

You can fire an event to give the player a badge in the server.

You could put the code inside a server script and define player by putting the code inside “game.Players.PlayerAdded:Connect(function(Player)”

Not really, hes doing this inside a tool.

how would you fire an event for Tool.Activated?

It should be :
-create a remote event
-Fire it whenvever the tool is activated
-Give the badge to the server on the server side.


tool.Activated:Connect(function()
             game.ReplicatedStorage:WaitForChild("RemoteEvent"):FireServer() 
end)
1 Like

Then on the server side you can just do the same thing to the old script but the player being a perameters in the OnclientEvent.

It should be :
-create a remote event
-Fire it whenvever the tool is activated
-Give the badge to the server on the server side.

tool.Activated:Connect(function()
             game.ReplicatedStorage:WaitForChild("RemoteEvent"):FireServer() 
end)

On the server side:

local IDToAward = 2128438468 --Replace this with your BadgeID
local BadgeService = game:GetService("BadgeService")

game.ReplicatedStorage:WaitForChild("RemoteEvent").OnServerEvent:Connect(function(player)
              BadgeService:AwardBadge(player.UserId, IDToAward)
              wait(1)
              player:Kick("You got the Pink Sauce!!!")
end)

I hope this help @Jordan6495

is this all in the same script?

No one is in the tool script the other is in server script service.

it doesnt work, i put the one in tool and the other in server script service.
It also doesnt kick either so i think its a problem with the event

If so then maybe i type wrong some where. You can learn about fire server and connect it your self.

Try this:

local BadgeID = 2128438468
local BadgeService = game:GetService("BadgeService")
local Players = game:GetService("Players")
local tool = script.Parent

local function onActivation()
	local Player = Players:FindFirstChild(tool.Parent.Name)
	local success,result = pcall(function()
		return BadgeService:UserHasBadgeAsync(Player.UserId,BadgeID)
	end)
	if success then
		if not result then
			BadgeService:AwardBadge(Player.UserId,BadgeID)
		end
	end
	task.wait(1)
	Player:Kick("You got the Pink Sauce!!!")
end

tool.Activated:Connect(onActivation)

[Server Script]

I dont think server script can run on tool.Activated.

They absolutely can. Check it out and see.
For me it worked.

doesnt say i got the badge, it did kick though

If you tested it in studio, it won’t give the badge.