Hello! I’ve been working on a game that’s like a badge hunt, but it’s randomized and every badge falls from the sky. [It’s kinda like a lag test game howerver.] Lets say a player touches it, a player should first, get the badge, then the block self-destructs. While it does work, it really gets laggy, and it stops registering people touching the brick, and it takes many minutes for it to register, and I feel like it might be because people already touching it are clogging up things.
How would I make a system where players who already have the badge can’t activate the script, while players who don’t have it can activate the script? [Script Below]
function OnTouch(part)
if (part.Parent:FindFirstChild("Humanoid") ~= nil) then
local p = game.Players:GetPlayerFromCharacter(part.Parent)
local h = part.Parent:FindFirstChild("Humanoid")
if (p ~= nil) and h.Health > 0 then
local b = game:GetService("BadgeService")
b:AwardBadge(p.userId, ExampleBadgeID)
script.Parent:Destroy()
end
end
end
script.Parent.Touched:connect(OnTouch)