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

How do I make this part give you a badge on touch?

Asked by
EpicLilC 150
8 years ago
local badgeID =356818734  -->Put the badges ID there
local badgeService = game:GetService("BadgeService")
function onTouch(player)
    wait(1)
    badgeService:AwardBadge(player.userId, badgeID)
end
game.Workspace.Badge.Touched:connect(onTouch)

I was looking in the roblox wiki and I saw the scripts for how to make badges. I didn't see one for how to make a part give you a badge when you touch it, so I messed around with a badge script from the wiki. I tested it out and it says "userId is not a valid member of part". What does that mean and how do I fix it?

1 answer

Log in to vote
0
Answered by 8 years ago

The parameter of Touched is the part that touches the part with the touched event. You can use GetPlayerFromCharacter to get the player, which has the userID. Your script errors because "player" is actually a part, which does not have member called "userId", and not the player.

local badgeID =356818734  -->Put the badges ID there
local badgeService = game:GetService("BadgeService")
local debounce = false;
function onTouch(part)
    if part.Parent.Humanoid and not debounce then --if part is a member of a player's character
        debounce = true
        local player = game.Players:GetPlayerFromCharacter(part.Parent)
        badgeService:AwardBadge(player.userId, badgeID)
        wait(1)
        debounce = false
    end
end
game.Workspace.Badge.Touched:connect(onTouch)

The debounce is to prevent the event from rapidly activating.

Ad

Answer this question