Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Why does my beeping blocks doesn't work at all?

Asked by 5 years ago

Ok so, i hate working with childrens functions, i don't know why it doesn't work. I'm trying to make these beep blocks from Mario Galaxy.

(If you don't know how these blocks work, you should check this video https://youtu.be/EN4X7x4w65Q?t=3m9s)

But with this script, the blocks just do nothing at all.

Please, i need some help!

local g = script.Parent.Green
local o = script.Parent.Orange
local sound1 = script.Parent.Sound1
local sound2 = script.Parent.Sound2

function gr()
if gr == true then  
script.Parent.Sound1:Play()
for _, child in pairs(g:GetChildren()) do
    child.Reflectance = 0.4
    wait(0.1)
    child.Reflectance = 0
end
gr = false
end
end

function gf()
    if gf == true then
    script.Parent.Sound2:Play()
    for _, child in pairs(g:GetChildren()) do
        child.Transparency = 1
        child.CanCollide = false

    end
        for _, child in pairs(o:GetChildren()) do
        child.Transparency = 0
        child.CanCollide = true
    end
gf = false
end
end

function ore()
if ore == true then 
script.Parent.Sound1:Play()
for _, child in pairs(o:GetChildren()) do
    child.Reflectance = 0.4
    wait(0.1)
    child.Reflectance = 0
end
ore = false
end
end

function of()
    if of == true then
    script.Parent.Sound2:Play()
    for _, child in pairs(o:GetChildren()) do
        child.Transparency = 1
        child.CanCollide = false

    end
        for _, child in pairs(g:GetChildren()) do
        child.Transparency = 0
        child.CanCollide = true
        end
    of = false
end
end




while true do
wait(1.5)
gr = true
wait(0.7)
gr = true
wait(0.7)
gr = true
wait(0.7)
gf = true
wait(1.5)
ore = true
wait(0.7)
ore = true
wait(0.7)
ore = true
wait(0.7)
of = true
end

0
You have nothing to run the function the if statement is not checking constantly. You would need to place the if statement inside of a loop. TiredMelon 405 — 5y
0
I updated my answer again. protectiveebob 221 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

psst it's really easy to call functions.

local g = script.Parent.Green
local o = script.Parent.Orange
local sound1 = script.Parent.Sound1
local sound2 = script.Parent.Sound2

function gr() -- you set gr as the name for your function, you cannot reuse variable names
-- if you want a debounce I can fix it for you.
    script.Parent.Sound1:Play()
    for _, child in pairs(g:GetChildren()) do
        child.Reflectance = 0.4
    end
    wait(.1)
    for _, child in pairs(g:GetChildren()) do
        child.Reflectance = 0
    end
end

function gf()
    script.Parent.Sound2:Play()
    for _, child in pairs(g:GetChildren()) do
        child.Transparency = 1
        child.CanCollide = false
    end
    wait(.1)
    for _, child in pairs(o:GetChildren()) do
        child.Transparency = 0
        child.CanCollide = true
    end
end

function ore()
script.Parent.Sound1:Play()
for _, child in pairs(o:GetChildren()) do
    child.Reflectance = 0.4
end
wait(.1)
for _, child in pairs(o:GetChildren()) do
    child.Reflectance = 0
end
end

function of()
    script.Parent.Sound2:Play()
    for _, child in pairs(o:GetChildren()) do
        child.Transparency = 1
        child.CanCollide = false
    end
    wait(.1)
    for _, child in pairs(g:GetChildren()) do
        child.Transparency = 0
        child.CanCollide = true
    end
end




while true do
wait(1.5)
gr() -- that's how you run a function
wait(0.7)
gr()
wait(0.7)
gr()
wait(0.7)
gf()
wait(1.5)
ore()
wait(0.7)
ore()
wait(0.7)
ore()
wait(0.7)
of()
end

1
Ok so it working but their reflectance change one by one but their transparency change all at the same time. Can you do that their reflectance change all at the same time? dingding2002 14 — 5y
0
I'm not sure if that's the event you were going for, but the idea is there. Just add wait()s in the correct spots. protectiveebob 221 — 5y
1
Their reflectance still change one by one dingding2002 14 — 5y
0
Oh, I'm sorry, I read it backwards. Just remove the wait()s in the functions. Here, I'll fix it. protectiveebob 221 — 5y
View all comments (2 more)
0
There, I fixed it again. protectiveebob 221 — 5y
0
It work, thanks! dingding2002 14 — 5y
Ad

Answer this question