Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

2 comments

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.

0

I updated my answer again.

1 answer

✓ Accepted answer

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

6 comments

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?

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.

1

Their reflectance still change one by one

0

Oh, I'm sorry, I read it backwards. Just remove the wait()s in the functions. Here, I'll fix it.

0

There, I fixed it again.

0

It work, thanks!

This discussion is preserved as it was. New answers, comments, and votes are closed.