I need help for working badge giver

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:
Screenshot 2024-08-17 013307
this is working, however i dont know how to make a script that award the badge if the value reaches 15

2 Likes

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 might also want to check if the user has the badge already using BadgeService:UserHasBadgeAsync.

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)
1 Like

um i do not know how to do that

it is a script in serverscriptservice right?

It could be if that is where you want to put it.

oh yea and what i put in clicks?

I’m not sure what you are asking here. Can you clarify?

click = {??} what i need to put there

Why do you think you need to put something there?

idk, btw it gives me errors on mouseclick

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.

ok, i understand you and btw i kinda know scripting but i really dont understand what is that for

The purpose of the clicks table is to keep track of the number of clicks that each player currently has by using the player’s instance as a key.

ok but i didnt mean that, i mean the mouseclick event that i dont know how to complete it

ok, i read some stuff, i understood and i finished that, thanks btw