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

What's incorrect about this function script?

Absolutely nothing happens. The number value does not change, which is the first part.

p = script.Parent
n = script.Parent.Number
gr = workspace.GreyRim
u1 = workspace.Union1
u2 = workspace.Union2

script.Parent.Touched(function()
	if n.Value == 1 then
		script.Parent.Script.Disabled = true
			n.Value = 0
		script.Parent.BrickColor = BrickColor.new("Bright blue")
		
		for index,v in pairs(workspace.Glass:GetChildren()) do
			for i = 1,8 do
				v.Transparency = .7
				v.CanCollide = true
			end
		end
		
		for i = 1,160 do
			p.CFrame = p.CFrame * CFrame.new(0,.135,0)
			gr.CFrame = gr.CFrame * CFrame.new(0,.135,0)
			u1.CFrame = u1.CFrame * CFrame.new(0,.135,0)
			u2.CFrame = u2.CFrame * CFrame.new(0,.135,0)
			wait(.05)
		end
		
		wait(1)
			p.BrickColor = BrickColor.new("Medium blue")
		n.Value = 1
		
		for index,v in pairs(workspace.Glass:GetChildren()) do
			for i = 1,8 do
				v.Transparency = 1
				v.CanCollide = false
			end
		end
			wait(5)
		script.Parent.Script.Disabled = true
	end
	
	
	
	if n.Value == 0 then
		script.Parent.Script.Disabled = true
			n.Value = 1
		script.Parent.BrickColor = BrickColor.new("Bright blue")
		
		for index,v in pairs(workspace.Glass:GetChildren()) do
			for i = 1,8 do
				v.Transparency = .7
				v.CanCollide = true
			end
		end
		
		for i = 1,160 do
			p.CFrame = p.CFrame * CFrame.new(0,-.135,0)
			gr.CFrame = gr.CFrame * CFrame.new(0,-.135,0)
			u1.CFrame = u1.CFrame * CFrame.new(0,-.135,0)
			u2.CFrame = u2.CFrame * CFrame.new(0,-.135,0)
			wait(.05)
		end
		
		wait(1)
			p.BrickColor = BrickColor.new("Medium blue")
		n.Value = 1
		
		for index,v in pairs(workspace.Glass:GetChildren()) do
			for i = 1,8 do
				v.Transparency = 1
				v.CanCollide = false
			end
		end
			wait(5)
		script.Parent.Script.Disabled = true
	end
end)

2 comments

0

Are you sure that the number value is even set to 1 or 0? If not, that's the problem...otherwise, I don't see anything else wrong with this script.

0

You never connected your function to any event. So nothing will happen

1 answer

✓ Accepted answer

Whoops, sorry about the comment above. I noticed what the problem was right after I posted that. You didn't connect the function to the event. Try this:

p = script.Parent
n = script.Parent.Number
gr = workspace.GreyRim
u1 = workspace.Union1
u2 = workspace.Union2

script.Parent.Touched:connect(function() --You just needed to add a ":connect" here.
    if n.Value == 1 then
        script.Parent.Script.Disabled = true
            n.Value = 0
        script.Parent.BrickColor = BrickColor.new("Bright blue")

        for index,v in pairs(workspace.Glass:GetChildren()) do
            for i = 1,8 do
                v.Transparency = .7
                v.CanCollide = true
            end
        end

        for i = 1,160 do
            p.CFrame = p.CFrame * CFrame.new(0,.135,0)
            gr.CFrame = gr.CFrame * CFrame.new(0,.135,0)
            u1.CFrame = u1.CFrame * CFrame.new(0,.135,0)
            u2.CFrame = u2.CFrame * CFrame.new(0,.135,0)
            wait(.05)
        end

        wait(1)
            p.BrickColor = BrickColor.new("Medium blue")
        n.Value = 1

        for index,v in pairs(workspace.Glass:GetChildren()) do
            for i = 1,8 do
                v.Transparency = 1
                v.CanCollide = false
            end
        end
            wait(5)
        script.Parent.Script.Disabled = true
    end



    if n.Value == 0 then
        script.Parent.Script.Disabled = true
            n.Value = 1
        script.Parent.BrickColor = BrickColor.new("Bright blue")

        for index,v in pairs(workspace.Glass:GetChildren()) do
            for i = 1,8 do
                v.Transparency = .7
                v.CanCollide = true
            end
        end

        for i = 1,160 do
            p.CFrame = p.CFrame * CFrame.new(0,-.135,0)
            gr.CFrame = gr.CFrame * CFrame.new(0,-.135,0)
            u1.CFrame = u1.CFrame * CFrame.new(0,-.135,0)
            u2.CFrame = u2.CFrame * CFrame.new(0,-.135,0)
            wait(.05)
        end

        wait(1)
            p.BrickColor = BrickColor.new("Medium blue")
        n.Value = 1

        for index,v in pairs(workspace.Glass:GetChildren()) do
            for i = 1,8 do
                v.Transparency = 1
                v.CanCollide = false
            end
        end
            wait(5)
        script.Parent.Script.Disabled = true
    end
end)

Try it now. I think that this should work. If not, please leave a comment below, and I'll see what I can do to fix it. Hope I helped :P

4 comments

0

Thank you so much. I haven't scripted anything all year, so I was having trouble remembering stuff.

0

Nevermind, it still does nothing.

0

Okay, I got it to work now. Thanks

0

No prob. Glad I could help.

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