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

What's incorrect about this function script?

Asked by 9 years ago

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)
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. dyler3 1510 — 9y
0
You never connected your function to any event. So nothing will happen Goulstem 8144 — 9y

1 answer

Log in to vote
2
Answered by
dyler3 1510 Moderation Voter
9 years ago

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

0
Thank you so much. I haven't scripted anything all year, so I was having trouble remembering stuff. Lightdrago 95 — 9y
0
Nevermind, it still does nothing. Lightdrago 95 — 9y
0
Okay, I got it to work now. Thanks Lightdrago 95 — 9y
0
No prob. Glad I could help. dyler3 1510 — 9y
Ad

Answer this question