Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

On Mouseclick award badge?

To start off, i have everything loaded, (BadgeID value, and the id in it, and clickdetector.)

This script was suggested by mohammed1336, i recently posted a question on discord but he gave me a script for this and it's not working so I've decided to ask it here.

script.Parent.ClickDetector.MouseClick:Connect(function(part)
   if part.Parent:FindFirstChildOfClass("Humanoid") then
        local p = game.Players:GetPlayerFromCharacter(part.Parent)
        if (p ~= nil) then
            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)

So someone basically clicks the egg (its for the badge) and they get awarded a badge.

1 answer

✓ Accepted answer

The Script you've provided is almost perfect, except whomever passed this Script off to you thought that ClickDetector.MouseClick provided the Part Clicked as an argument. This is wrong. It actually provides the Player who Clicked the Part. This will make everything attempted quite a lot easier, it should look like so

local Part = script.Parent --// Part was always given.
Part.ClickDetector.MouseClick:Connect(function(Player)
    if (game.Players:FindFirstChild(Player.Name)) then
         print("Awarding BadgeID: " ..Part.BadgeID.Value.. " to UserID: ".. Player.UserId)
         local BadgeService = game:GetService("BadgeService")
         BadgeService:AwardBadge(Player.UserId, Part.BadgeID.Value)
    end
end)

Hope this helps! if so, don't forget to accept the answer! For more information about ClickDetectors visit this wiki page.

3 comments

0

use if game.Players:FindFirstChild(Player.Name) then

0

Actually this is stupid. Why are you indexing the Player from the Players service like this.

0

Works well.

This discussion is preserved as it was. New answers, comments, and votes are closed.