Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to award a badge when you click a brick?

Asked by 9 years ago

Award badge when you clicked on a brick doesn't work I tryed to make one but i won't work

help me Thanks :P

wait (2)
print("Badge Awarder Loaded. BadgeID: " .. script.Parent.BadgeID.Value)



Part789 = script.Part789
p = script.Parent.Players


function onClicked()
    if (script.Part789:FindFirstChild("Humanoid") ~= nil) then
        if (p ~= nil) then
            local BadgeID = 210342277 -- Badge id
            print("Awarding BadgeID: " ..script.Parent.BadgeID.Value .. " to UserID: " .. p.userId)
            local b = game:GetService("BadgeService")
            b:AwardBadge(p.userId, script.Parent.BadgeID.Value)
        end
    end
end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

1 answer

Log in to vote
1
Answered by
Shawnyg 4330 Trusted Badge of Merit Snack Break Moderation Voter Community Moderator
9 years ago

The way you defined 'p' was incorrect. Pardon if I re-write your code a bit, but it's just how I'm used to it.

wait (2)
print("Badge Awarder Loaded. BadgeID: " .. script.Parent.BadgeID.Value)



Part789 = script.Part789



script.Parent.ClickDetector.MouseClick:connect(function(p)
    if (script.Part789:FindFirstChild("Humanoid") ~= nil) then -- I hope this isn't checking for an actual Player's humanoid
        if (p ~= nil) then -- This line isn't really necessary since nothing else can click
            local BadgeID = 210342277 -- Badge id
            print("Awarding BadgeID: " ..script.Parent.BadgeID.Value .. " to UserID: " .. p.userId)
            local b = game:GetService("BadgeService")
            b:AwardBadge(p.userId, script.Parent.BadgeID.Value)
        end
    end
end)

0
Thanks :) i didn't see that minetrackmania 186 — 9y
0
No problem. Shawnyg 4330 — 9y
Ad

Answer this question