Make a door that need a badge

Good night’s developers, i tried with different scripts make a door that needs a badge.

local Player = game.Players.LocalPlayer
local BadgeService = game:GetService(“BadgeService”)

local BadgeTable = {
{
Door = game.Workspace.PLV2.BD1,
Door2 = game.Workspace.PLV3.BD2,
Door3 = game.Workspace.PLV4.BD3,
BadgeId = 2149166541,
BadgeId2 = 2149250650,
BadgeId3 = 2149504995,
}
}

for LoopNum, Badge in pairs (BadgeTable) do
if BadgeService:UserHasBadgeAsync(Player.UserId,Badge.BadgeId) then
Badge.Door.CanCollide = false
end
end

for LoopNum, Badge in pairs (BadgeTable) do
if BadgeService:UserHasBadgeAsync(Player.UserId,Badge.BadgeId2) then
Badge.Door2.CanCollide = false
end
end

for LoopNum, Badge in pairs (BadgeTable) do
if BadgeService:UserHasBadgeAsync(Player.UserId,Badge.BadgeId3) then
Badge.Door3.CanCollide = false
end
end

That was an example of a script that doesn’t works
image-129

3 Likes

You don’t need to loop through the table 3 times you could do it all at once. Here’s the code that should work:

local Player = game.Players.LocalPlayer
local BadgeService = game:GetService(“BadgeService”)

local BadgeTable = {
Badge1 = {game.Workspace.PLV2.BD1,2149166541},
Badge2 = {game.Workspace.PLV3.BD2, 2149250650},
Badge3 = {game.Workspace.PLV4.BD3, 2149504995}
}
for _, Badge in pairs (BadgeTable) do
if BadgeService:UserHasBadgeAsync(Player.UserId,Badge[2]) then
Badge[1].CanCollide = false
end
end
2 Likes

cries


(I only changed the position of BD1 because I thought it would fix it)