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