So I want to make, if a player touch 3 button, they will get the badge. This is my script:
local badgeservice = game:GetService("BadgeService")
local id = 000
local debounce = true
script.Parent.ClickDetector.MouseClick:Connect(function(hit)
debounce = false
game.ReplicatedStorage.Counter.Value = game.ReplicatedStorage.Counter.Value + 1
if game.ReplicatedStorage.Counter.Value == 3 then
if hit.Parent:FindFirstChild ("Humanoid") then
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
badgeservice:AwardBadge (plr.UserId, id)
end
end
script.Parent:Destroy()
end)
MouseClick gets the player who clicks the ClickDetector, not whatever hit it. I believe you’re confusing this with Touched. Try the following and let me know if it works out for you.
local BS = game:GetService("BadgeService")
local id = 000
script.Parent.ClickDetector.MouseClick:Connect(function(plr)
game.ReplicatedStorage.Counter.Value = game.ReplicatedStorage.Counter.Value + 1
if game.ReplicatedStorage.Counter.Value == 3 then
BS:AwardBadge(plr.UserId, id)
end
end)