Script to award badge not working

I wrote a script to award a badge when the player gets a certain amount of points, but it is not working. I am still a beginner. Thanks!

local BadgeService = game:GetService("BadgeService")

while true do

local player = game:GetService("Players").LocalPlayer

if player.leaderstats.Points.Value >= 280 then

print("CHAINSAW")

BadgeService:AwardBadge(player.UserId, 2124653614)

end

end
1 Like

Two things. For one, you have no wait(). This will exhaust the execution time. As for the other thing, is this in a LocalScript? LocalScripts can not award badges, and the points can be manipulated. This should fix your issue:

local BadgeService = game:GetService("BadgeService")

while true do

local player = game:GetService("Players").LocalPlayer

if player.leaderstats.Points.Value >= 280 then

print("CHAINSAW")

BadgeService:AwardBadge(player.UserId, 2124653614)

end
wait()
end
1 Like

I did put this script in ServerScriptStorage

It must be in ServerScriptService.

Is this code written in a LocalScript? If so, LocalScript’s don’t run in SSS. Move it to StarterGui or someplace else, like StarterPlayerScripts.

You can not award a badge for the client’s side, as I said.

No, this is a regular script in ServerScriptStorage

First thing I see is that you’re doing "if the player’s points are over 280, print “CHAINSAW”, which can cause your game to lag because you’re constantly printing CHAINSAW, overloading the game.

Please read my first post, as I explain everything.

How long of a wait should I add?

You can just copy and paste my script.

Okay, I guess I will remove that once this script works, but it doesn’t work yet

Yeah, I added wait() but it still doesn’t work

Where? It has to NOT be in the if statement area, as it will be conditional and break.

Did you indent the code properly? Or did DevForum format it like that automatically

local BadgeService = game:GetService("BadgeService")

while true do

local player = game:GetService("Players").LocalPlayer

if player.leaderstats.Points.Value >= 280 then

print("CHAINSAW")

BadgeService:AwardBadge(player.UserId, 2124653614)

end
wait()
end

You need to change the localplayer part. You are not doing this from the client side, thus having no local player. Instead you should do this:

local BadgeService = game:GetService("BadgeService")

while true do

for i, player in pairs(game.Players:GetPlayers() do
if player.leaderstats.Points.Value >= 280 then

print("CHAINSAW")

BadgeService:AwardBadge(player.UserId, 2124653614)

end
end
wait(1)
end

I did it like I put it in, so yeah, I have indents

That is not the issue.

Writing this to bypass characters.
Writing this to bypasscharacters.

Please read my post.

Writing this to bypass characters.Writing this to bypass characters.

You can’t call LocalPlayer from a Server Script. Use a playerAdded function.