So I am making Obby, where the stages are invisible and appear when you touch a button. This is my button script and each variable - (I think it’s called a variable) is another block, the variable is linked to the part. Each part’s CanCollide and Transpanency is changed when the button is pressed and when the timer runs out.
Script:
for i,v in pairs(game.Workspace["Obby Structure"]["Levels 1-10"]["7"]["Blocks"]:GetChildren()) do
if v:IsA("Part") then ----checking if its a part
v.CanCollide= false
v.Transparency = 1
end
for i, v in pairs are like what you said
where v become the instance or value and i become the index
local Blocks = workspace:WaitForChild("Obby Structure"):WaitForChild("Levels 1-10"):WaitForChild("7"):WaitForChild("Blocks") -- Don't know if I misspelled anything here, make sure to check.
for i = 1, 16 do -- This loop will repeat 16 times.
local Part = Blocks["Part"..tostring(i)] -- Get the part
Part.CanCollide = true
game:GetService("TweenService"):Create(Part, TweenInfo.new(0.3), {Transparency = 0}):Play() -- Tween the parts transparency to 0 in 0.3 seconds.
end
script.Parent.BrickColor = BrickColor.new("Dark green")
local Blocks = workspace:WaitForChild("Obby Structure"):WaitForChild("Levels 1-10"):WaitForChild("7"):WaitForChild("Blocks")
print("child found")
startPosition = Vector3.new(-1.1, 0.9, 345.1) --Change to Coords off button top
local a = game.Workspace["Obby Structure"]["Levels 1-10"]["7"]["Blocks"].Part1
a.CanCollide = false
a.Transparency = 1
print("a done")
local b = game.Workspace["Obby Structure"]["Levels 1-10"]["7"]["Blocks"].Part2
b.CanCollide = false
b.Transparency = 1
local c = game.Workspace["Obby Structure"]["Levels 1-10"]["7"]["Blocks"].Part3
c.CanCollide = false
c.Transparency = 1
local d = game.Workspace["Obby Structure"]["Levels 1-10"]["7"]["Blocks"].Part4
d.CanCollide = false
d.Transparency = 1
local e = game.Workspace["Obby Structure"]["Levels 1-10"]["7"]["Blocks"].Part5
e.CanCollide = false
e.Transparency = 1
local f = game.Workspace["Obby Structure"]["Levels 1-10"]["7"]["Blocks"].Part6
f.CanCollide = false
f.Transparency = 1
local g = game.Workspace["Obby Structure"]["Levels 1-10"]["7"]["Blocks"].Part7
g.CanCollide = false
g.Transparency = 1
local h = game.Workspace["Obby Structure"]["Levels 1-10"]["7"]["Blocks"].Part8
h.CanCollide = false
h.Transparency = 1
local i = game.Workspace["Obby Structure"]["Levels 1-10"]["7"]["Blocks"].Part10
i.CanCollide = false
i.Transparency = 1
local j = game.Workspace["Obby Structure"]["Levels 1-10"]["7"]["Blocks"].Part11
j.CanCollide = false
j.Transparency = 1
local k = game.Workspace["Obby Structure"]["Levels 1-10"]["7"]["Blocks"].Part12
k.CanCollide = false
k.Transparency = 1
local l = game.Workspace["Obby Structure"]["Levels 1-10"]["7"]["Blocks"].Part13
l.CanCollide = false
l.Transparency = 1
local m = game.Workspace["Obby Structure"]["Levels 1-10"]["7"]["Blocks"].Part14
m.CanCollide = false
m.Transparency = 1
local n = game.Workspace["Obby Structure"]["Levels 1-10"]["7"]["Blocks"].Part15
n.CanCollide = false
n.Transparency = 1
local o = game.Workspace["Obby Structure"]["Levels 1-10"]["7"]["Blocks"].Part16
o.CanCollide = false
o.Transparency = 1
local p = game.Workspace["Obby Structure"]["Levels 1-10"]["7"]["Blocks"].Part9
p.CanCollide = false
p.Transparency = 1
local Button = game.Workspace["Obby Structure"]["Levels 1-10"]["7"]["Button"].Button.Top
print("button found")
local buttonactive = false
function displaytime(countdowntime)
print("function started")
local timer = Instance.new ("BillboardGui", game.Workspace["Obby Structure"]["Levels 1-10"]["7"]["Button"].Button.Top)
timer.Size = UDim2.new(0,50,0,50)
timer.StudsOffset = Vector3.new(0,5,0)
timer.AlwaysOnTop = true
timer.Enabled = true
local obstruction = Button
obstruction.Position = Vector3.new(-1.1, 0.4, 345.1) -- coords of button top (y-0.5)
script.Parent.BrickColor = BrickColor.new("Really red")
print("upto new part")
for i = 1, 16 do -- This loop will repeat 16 times.
local Part = Blocks["Part"..tostring(i)] -- Get the part
Part.CanCollide = true
game:GetService("TweenService"):Create(Part, TweenInfo.new(0.3), {Transparency = 0}):Play() -- Tween the parts transparency to 0 in 0.3 seconds.
print("first displaytime sucess")
local timertxt = Instance.new("TextBox", game.Workspace["Obby Structure"]["Levels 1-10"]["7"]["Button"].Button.Top)
timertxt.Parent = timer
timertxt.Size = UDim2.new(0,50,0,50)
timertxt.TextScaled = true
timertxt.TextColor3 = Color3.new(255,255,255)
timertxt.BackgroundColor3 = Color3.new(0,0,0)
timertxt.BorderColor3 = Color3.new(0,0,0)
timertxt.BackgroundTransparency = 1
local bincountdown = countdowntime
repeat
timertxt.Text = tostring(bincountdown)
bincountdown = bincountdown - 1
wait(1)
until
bincountdown < 1
obstruction.Position = Vector3.new(-1.1, 0.9, 345.1)
timer.Enabled = false
buttonactive = false
a.CanCollide = false
b.CanCollide = false
c.CanCollide = false
d.CanCollide = false
e.CanCollide = false
f.CanCollide = false
g.CanCollide = false
h.CanCollide = false
i.CanCollide = false
j.CanCollide = false
k.CanCollide = false
l.CanCollide = false
m.CanCollide = false
n.CanCollide = false
o.CanCollide = false
p.CanCollide = false
a.Transparency = 1
b.Transparency = 1
c.Transparency = 1
d.Transparency = 1
e.Transparency = 1
f.Transparency = 1
g.Transparency = 1
h.Transparency = 1
i.Transparency = 1
j.Transparency = 1
k.Transparency = 1
l.Transparency = 1
m.Transparency = 1
o.Transparency = 1
p.Transparency = 1
script.Parent.BrickColor = BrickColor.new("Dark green")
end
local function onTouch(hit)
if hit.Parent:FindFirstChild("Humanoid") then
if buttonactive == false then
buttonactive = true
displaytime(5)
else
print ("Error - Already active!")
end
end
end
script.Parent.Touched:Connect(onTouch)
end
I chose to add the block variable at the top and the “for” in the function
(I added prints to see where the script was breaking)
I scripted it like this, I added the block variable with the others and i added the rest in the function as it was were the “manual” property lines were written.
script.Parent.BrickColor = BrickColor.new("Dark green")
local Stage = workspace:WaitForChild("Obby Structure"):WaitForChild("Levels 1-10"):WaitForChild("7")
print("child found")
startPosition = Vector3.new(-1.1, 0.9, 345.1) --Change to Coords off button top
local Button = game.Workspace["Obby Structure"]["Levels 1-10"]["7"]["Button"].Button.Top
print("button found")
local buttonactive = false
function displaytime(countdowntime)
print("function started")
local timer = Instance.new ("BillboardGui", game.Workspace["Obby Structure"]["Levels 1-10"]["7"]["Button"].Button.Top)
timer.Size = UDim2.new(0,50,0,50)
timer.StudsOffset = Vector3.new(0,5,0)
timer.AlwaysOnTop = true
timer.Enabled = true
local obstruction = Button
obstruction.Position = Vector3.new(-1.1, 0.4, 345.1) -- coords of button top (y-0.5)
script.Parent.BrickColor = BrickColor.new("Really red")
print("upto new part")
for i,v in pairs(game.Workspace["Obby Structure"]["Levels 1-10"]["7"]["Blocks"]:GetChildren()) do
if v:IsA("Part") then ----checking if its a part
v.CanCollide = true
v.Transparency = 0
print("first displaytime sucess")
local timertxt = Instance.new("TextBox", game.Workspace["Obby Structure"]["Levels 1-10"]["7"]["Button"].Button.Top)
timertxt.Parent = timer
timertxt.Size = UDim2.new(0,50,0,50)
timertxt.TextScaled = true
timertxt.TextColor3 = Color3.new(255,255,255)
timertxt.BackgroundColor3 = Color3.new(0,0,0)
timertxt.BorderColor3 = Color3.new(0,0,0)
timertxt.BackgroundTransparency = 1
local bincountdown = countdowntime
repeat
timertxt.Text = tostring(bincountdown)
bincountdown = bincountdown - 1
wait(1)
until
bincountdown < 1
obstruction.Position = Vector3.new(-1.1, 0.9, 345.1)
timer.Enabled = false
buttonactive = false
for i,v in pairs(game.Workspace["Obby Structure"]["Levels 1-10"]["7"]["Blocks"]:GetChildren()) do
if v:IsA("Part") then ----checking if its a part
v.CanCollide = false
v.Transparency = 1
script.Parent.BrickColor = BrickColor.new("Dark green")
end
local function onTouch(hit)
if hit.Parent:FindFirstChild("Humanoid") then
if buttonactive == false then
buttonactive = true
displaytime(5)
else
print ("Error - Already active!")
end
end
end
script.Parent.Touched:Connect(onTouch)
end
end
end
end
But now nothing works, the blocks start visible. The Button doesn’t activate. How do i fix this?
Also there are no errors appearing
for i, #game.Workspace["Obby Structure"]["Levels 1-10"]["7"]["Blocks"]:GetChildren() do
local Part = Blocks["Part"..tostring(i)]
Part.CanCollide = true
game:GetService("TweenService"):Create(Part, TweenInfo.new(0.3), {Transparency = 0}):Play()
end