-
So for my game, I want to make a brick that when a player touches it, it gives them a badge.
-
The issue being, I also have NPCs around the map that can also touch the brick, which puts errors into the code whenever trying to find the UserId of the NPC (which isn’t a player)
-
this is my current code
function onTouch(hit)
local character = hit.Parent
if game.Players:WaitForChild(character.Name) ~= nil then
local badgeservice = game:GetService("BadgeService")
local id = ID
if not badgeservice:UserHasBadgeAsync(game.Players[character.Name].UserId, id) then
badgeservice:AwardBadge(game.Players[character.Name].UserId, id)
end
end
end
script.Parent.Touched:connect(onTouch)
so it gives out the badge but whenever an NPC touches it it keeps outputting Infinite Yield, is there a way to specifically check if the model is a player or NPC?