Anybody know why this script isn’t working? Only some parts go transparent… (yes I checked the model, all the parts are in it)
open1.MouseClick:Connect(function(player)
if player.Team == game.Teams["A Team"] then
for i,v in ipairs(script.Parent.Parent.GarageDoor1:GetChildren()) do
wait(.02)
v.Transparency = 1
v.CanCollide = false
wait(4)
v.Transparency = 0
v.CanCollide = true
end
end
end)
open2.MouseClick:Connect(function(player)
if player.Team == game.Teams["A Team"] then
for i,v in ipairs(script.Parent.Parent.GarageDoor2:GetChildren()) do
v.Transparency = 1
v.CanCollide = false
wait(4)
v.Transparency = 0
v.CanCollide = true
end
end
end)
local function open1(player)
if player.Team == game.Teams["A Team"] then
for i,v in ipairs(script.Parent.Parent.GarageDoor1:GetChildren()) do
coroutine.wrap(function()
wait(0.2)
v.Transparency = 1
v.CanCollide = false
wait(4)
v.Transparency = 0
v.CanCollide = true
end)()
end
end
end
open1.MouseClick:Connect(open1)
local function open2(player)
if player.Team == game.Teams["A Team"] then
for i,v in ipairs(script.Parent.Parent.GarageDoor2:GetChildren()) do
coroutine.wrap(function()
v.Transparency = 1
v.CanCollide = false
wait(4)
v.Transparency = 0
v.CanCollide = true
end)()
end
end
end
open2.MouseClick:Connect(open2)
local Teams = game:GetService("Teams")
open1.MouseClick:Connect(function(player)
if player.Team == Teams["A Team"] then
print("Found a player who has a valid team")
for i,v in ipairs(script.Parent.Parent.GarageDoor1:GetChildren()) do
print("Iterating through the loop", v)
wait(.02)
v.Transparency = 1
v.CanCollide = false
wait(4)
v.Transparency = 0
v.CanCollide = true
end
end
end)
open2.MouseClick:Connect(function(player)
if player.Team == Teams["A Team"] then
print("Found a player who has a valid team")
for i,v in ipairs(script.Parent.Parent.GarageDoor2:GetChildren()) do
print("Iterating through the loop", v)
v.Transparency = 1
v.CanCollide = false
wait(4)
v.Transparency = 0
v.CanCollide = true
end
end
end)
Also side note, but your wait(4) is slowly going through all parts inside the loop which could be the reason why “some parts” are going transparent, as it’s going extremely slow
um alright, so quick question you said that some part only go transparent? my question is well do you want all parts in the model to be transparent at the same time? since the loop sets the transparency to 1 then waits 4 seconds for it go to back for every 1 irrigation on a part so the loop is gonna yield every 4 seconds and set it back. my solution for this is add another for i loop to set it back.
here what i mean by adding another for i loop
local function Clicked(Player)
for _,v in pairs(Model:GetChildren()) do
if v:IsA("BasePart") then --checks if its a part
v.Transparecy = 1
end
end
wait(4)
for _,v in pairs(Model:GetChildren()) do
if v:IsA("BasePart") then --checks if its a part
v.Transparecy = 0
end
end
end
ClickDectector:Connect(Clicked)
(im sorry if you didn’t undstand meh im kinda new here.)
I normally wouldn’t do wait, but this is just for you to understand.
local Teams = game:GetService("Teams")
local CD = game.Workspace.Garage.ClickDetector
local Garage = CD.Parent
local function Open1(Player)
if Player.Team == Teams.Red then
for i,v in pairs(Garage:GetChildren()) do
if v:IsA("Part") then
v.Transparency = 1
Garage.Transparency = 1
end
end
wait(4)
for i,v in pairs(Garage:GetChildren()) do
if v:IsA("Part") then
v.Transparency = 0
Garage.Transparency = 0
end
end
end
end
CD.MouseClick:Connect(Open1)
As the above post mentioned You could probably just create 2 loops for each function when you click on the detectors:
local Teams = game:GetService("Teams")
local Model1 = script.Parent.Parent.GarageDoor1
local Model2 = script.Parent.Parent.GarageDoor2
open1.MouseClick:Connect(function(player)
if player.Team == Teams["A Team"] then
print("Found a player who has a valid team")
for i,v in ipairs(Model1:GetChildren()) do
v.Transparency = 1
v.CanCollide = false
end
wait(4)
for i,v in ipairs(Model1:GetChildren()) do
v.Transparency = 0
v.CanCollide = true
end
end
end)
open2.MouseClick:Connect(function(player)
if player.Team == Teams["A Team"] then
print("Found a player who has a valid team")
for i,v in ipairs(Model2:GetChildren()) do
v.Transparency = 1
v.CanCollide = false
end
wait(4)
for i,v in ipairs(Model2:GetChildren()) do
v.Transparency = 0
v.CanCollide = true
end
end
end)
Also @TFlanigan pairs/ipairs wouldn’t make any difference I believe
ipairs returns back the table in the ordered fashion it was delivered in
pairs just returns back the table in a randomized way