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

How should I make a script that gives you a badge using a touch event?

Asked by 4 years ago

I've been trying to figure out how to use a touch event badge script for a while now. I've tried multiple scripts, like this one.

local badgeID =123456789  -->Whatever your badge id is
local badgeService = game:GetService("BadgeService")
function onTouch(player)
    badgeService:AwardBadge(player.userId, badgeID)
end
game.Workspace.Badge.Touched:connect(onTouch)

That did not work. Do any of you know how to do this?

1 answer

Log in to vote
0
Answered by
rexhawk 222 Moderation Voter
4 years ago
Edited 4 years ago
local badgeService = game:GetService("BadgeService")
local players = game:GetService("Players")
local badgeID = 000000000

function onTouch(hit)
    local player = players:GetPlayerFromCharacter(hit.Parent)
    if player then
        badgeService:AwardBadge(player.UserId, badgeID)
    end
end

script.Parent.Touched:Connect(onTouch)

This script is meant to be placed within the brick you want to effect Make sure to change the badgeID value to the ID of your badge, and it should work

Ad

Answer this question