I need idea how to make Find The Button system but different. When someone will click the button, door will be: Transparency = 0.5 and CanCollide = false or player will be teleported to next level but here is a problem. I’m using StringValue named “Type” and I’m using 2 types: Door and Teleport. When Type value is door the door will be like I said earlier but when type is teleport the player will be teleported. Problem is here:
I don’t know how to get it all in one script I tried with in pairs but I had 5x in pairs and I was confused, is there other and better idea how to do it?
It will be easier to use for loops if you change the structure of your folders. Right now you are storing levels 3-11 as children of level 2, which is unnecessary (unless you have a really good reason to do that, it’s not very clean).
Once all levels have the same parent, you can use a single for loop to loop through all of the folders.
Could you show me the code that you tried? I’ll help you fix it.
I don’t really know what exactly you’re trying to do and how, so seeing your previous attempt will be helpful.
local folder = workspace.LeverSystem -- Your folder that you wish to check
for _, object in pairs(folder:GetDescendants()) do
if object:IsA("StringValue") and object.Name == "Type" then
-- Whatever you need to do
end
end
Essentially, :GetDescendants() checks the children’s children and so forth.
I did for loop for doors folder and levers folder. It work’s fine but, it prints 3x times and I am confused. I’m not good at scripting but I’m trying my best.
--// Variables
local LeverSystemFolder = workspace.LeverSystem
local Doors = LeverSystemFolder:WaitForChild("Doors")
local Levers = LeverSystemFolder:WaitForChild("Levers")
local Teleports = LeverSystemFolder:WaitForChild("Teleports")
for i, LeverMaps in pairs(Levers:GetChildren()) do
for i, levels in pairs(LeverMaps:GetChildren()) do
for i, DoorMaps in pairs(Doors:GetChildren()) do
for i, dlevels in pairs(DoorMaps:GetChildren()) do
for i, doorParts in pairs(dlevels.door:GetChildren()) do
if levels:FindFirstChild("lever") then
levels.lever.ClickDetector.MouseClick:Connect(function()
if levels.lever.Type.Value == "Door" and levels.Name == dlevels.Name then
if doorParts:IsA("Part") or doorParts:IsA("UnionOperation") then
doorParts.Transparency = 0.5
doorParts.CanCollide = false
print(dlevels.Name)
end
end
end)
end
end
end
end
end
end
I know it’s not what you’re asking, but I recommend you make a folder for each level and keep both the doors and levers together in it. It will make everything much easier.
If you want to use your current setup, then you should:
Loop through all levels (a for loop that goes through the numbers 1 to the max level).
Use GetDescendants to find the type inside the level (Use the index of the for loop to find the level folder that has the name “Level”…index).
If the type is door, use the index again to access the correct level folder inside the Doors folder. Then change the door’s properties.