function OnClick(part)
if (part.Parent:FindFirstChild("Humanoid") ~= nil) 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
script.Parent.ClickMe.Clicked:Connect(OnClick) -- script erored here
I dont know if this clicked is no longer a function or am i mispelling some words?
also how to make the brick instead of clicked also tappable with mobile?
Looks like you’re confusing clicked with touched a little bit here. If it were touched you could check for a humanoid in the part the touched the brick, but I believe in clicked your ‘part’ variable would actually return the player who clicked the object, not any part of their character, and thus there would be no point in checking for a humanoid.
I’m not too sure if it would work on mobile automatically or not, but you also need to change another part of your code. Right now you’re checking for a humanoid inside the player object and that is always going to not work. Your ‘part’ variable is literally the player object of the player who clicked the part. So I would rename it to Player or PlayerWhoClicked or something like that and then you can just drop the humanoid check and award the badge that way.
local b = game:GetService("BadgeService")-- get the badge service first so it doesn't re-get it every time someone clicks (this may not really make a difference on performance)
function OnClick(Player)--I changed your 'part' variable to Player because on MouseClick it returns the player object so I also got rid of the check for humanoid
if Player then --now just check that the player exists and grant them the badge
print("Awarding BadgeID: " ..script.Parent.BadgeID.Value .. " to UserID: " .. Player.userId)
b:AwardBadge(Player.userId, script.Parent.BadgeID.Value)
end
end
script.Parent.ClickMe.MouseClick:Connect(OnClick)