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
9 years ago
1local badgeID =356818734  -->Put the badges ID there
2local badgeService = game:GetService("BadgeService")
3function onTouch(player)
4    wait(1)
5    badgeService:AwardBadge(player.userId, badgeID)
6end
7game.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 9 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.

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

The debounce is to prevent the event from rapidly activating.

Ad

Answer this question