so i was making this game where u need to find all the potatoes around the map and when the value called “Potatoes” in “NoSaveValues” gets to 15 then player get a badge
but it isnt working, basically ive made a localscript in starterplayerscripts for each potato:
this is working, however i dont know how to make a script that award the badge if the value reaches 15
You use the BadgeService::AwardBadge function to award a badge to a player. A note is that this function must be called on the server. So you cannot use a local script.
You can store a local variable outside of the function you are connecting to the MouseClick event and increment it every time your function is invoked. It might be more advantageous to actually store all of the clicks for each player in a table assuming that you want each player to have to click 15 times.
Here is a guideline for what you could do:
local BadgeService = game:GetService("BadgeService")
local Players = game:GetService("Players")
local BADGE_ID = 123456
local clicks = {}
MouseClick:Connect(function(plr)
clicks[plr] = clicks[plr] + 1
if clicks[plr] == 15 and BadgeService:UserHasBadgeAsync(plr.UserId, BADGE_ID) == false then
BadgeService:AwardBadge(plr.UserId, BADGE_ID)
end
end)
Players.PlayerAdded:Connect(function(plr) clicks[plr] = 0 end)
Players.PlayerRemoving:Connect(function(plr) clicks[plr] = nil end)
I gave you a guide for how a script you would write might look like. I did not give you fully working code. I can help you work out the details, but I don’t really want to entertain doing all of the work for you.