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

Velocity help?!!!! Converyor belt help!

Asked by 8 years ago

ok, everything is correct, all the directories, what is going wrong!

while true do
    wait()
    if script.Parent.Configuration.SpeedValue == true then
        script.Parent.ConveyorPart1.Velocity = Vector3.new(0,0,5)
        script.Parent.ConveyorPart2.Velocity = Vector3.new(-5,0,0)
        script.Parent.ConveyorPart3.Velocity = Vector3.new(0,0,-5)
        script.Parent.ConveyorPart4.Velocity = Vector3.new(0,0,-5)
        script.Parent.ConveyorPart5.Velocity = Vector3.new(-5,0,0)
        script.Parent.ConveyorPart6.Velocity = Vector3.new(0,0,5)

        elseif script.Parent.Configuration.SpeedValue == false then
        script.Parent.ConveyorPart1.Velocity = Vector3.new(0,0,20)
        script.Parent.ConveyorPart2.Velocity = Vector3.new(-20,0,0)
        script.Parent.ConveyorPart3.Velocity = Vector3.new(0,0,-20)
        script.Parent.ConveyorPart4.Velocity = Vector3.new(0,0,-20)
        script.Parent.ConveyorPart5.Velocity = Vector3.new(-20,0,0)
        script.Parent.ConveyorPart6.Velocity = Vector3.new(0,0,20)

    end
end

2 answers

Log in to vote
0
Answered by 8 years ago

illuminatti

Ad
Log in to vote
1
Answered by
Marios2 360 Moderation Voter
8 years ago

Although you only explained what is wrong in the SH chat, you at least put effort beforehand so i will answer.

So let's make your script work and be as effecient as it can get.

Your while true do loop, although it does work, repeatedly checks an if statement. Bad practice. Also, to refer to a value of any kind (BooleanValue,NumberValue,IntValue etc.) you must refer to it's own value property.

So, before fixing the main script, i am going to show you the Changed event. In short, events are conditions that "fire" when they are met. To "hear" when the condition fires we must set up a listener. Let's do so for the Changed event:

script.Parent.Configuration.SpeedValue.Changed:connect(function(value)

In this case, when the Changed event fires, it activates the function it contains and provides the new value. The event fires when the value of the container changes. Speaking of which, the Changed event normally fires on when any property of an instance changes, but value containers are an exception and only fire on change of their value. So, let's complete the script:

script.Parent.Configuration.SpeedValue.Changed:connect(function(value)
    if value == true then
        script.Parent.ConveyorPart1.Velocity = Vector3.new(0,0,500)
        script.Parent.ConveyorPart2.Velocity = Vector3.new(-500,0,0)
        script.Parent.ConveyorPart3.Velocity = Vector3.new(0,0,-500)
        script.Parent.ConveyorPart4.Velocity = Vector3.new(0,0,-500)
        script.Parent.ConveyorPart5.Velocity = Vector3.new(-500,0,0)
        script.Parent.ConveyorPart6.Velocity = Vector3.new(0,0,500)
    else
        script.Parent.ConveyorPart1.Velocity = Vector3.new(0,0,20)
        script.Parent.ConveyorPart2.Velocity = Vector3.new(-20,0,0)
        script.Parent.ConveyorPart3.Velocity = Vector3.new(0,0,-20)
        script.Parent.ConveyorPart4.Velocity = Vector3.new(0,0,-20)
        script.Parent.ConveyorPart5.Velocity = Vector3.new(-20,0,0)
        script.Parent.ConveyorPart6.Velocity = Vector3.new(0,0,20)
    end
end

So, if the new value is true, the conveyor activates to it's maximum potential; else it goes slowly. And this is much more effecient than the previous script, and it also works.

Why does this work and not yours? Yours referred directly to the value container, in this case script.Parent.Configuration.SpeedValue. To get the value you'd have to do script.Parent.Configuration.SpeedValue.Value. We need not do that here because the event we set up gives us the value.

I hope you understood more about Lua, and helped!

Answer this question