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

Why wont the conveyor belt speed change?

Asked by 3 years ago

Hi I'm making a conveyor belt speed changer it can either increase or decrease the speed but for now I want it to increase the speed

so when I click the button the value changes but not the speed of the conveyor belt

the conveyor script:

local Number = game.Workspace.GameHandeler.Number.Value


while true do
script.Parent.Velocity = script.Parent.CFrame.lookVector *Number
    wait(0.1)
end

the click script:

local jam = script.Parent.Number.Value

local Clicker = game.Workspace.increasebutton.increas.Clickincrease


function Clicked()
    jam = jam + 10
end

Clicker.MouseClick:Connect(Clicked)

i'm using number values as my storage

I'm new to scripting so any tips would be nice!

1 answer

Log in to vote
0
Answered by 3 years ago

I believe you have to move the "local jam = script.Parent.Number.Value" to inside of the function on the click script. I think it'll work if you do this:

local Clicker = game.Workspace.increasebutton.increas.Clickincrease


function Clicked()
    local jam = script.Parent.Number.Value
    jam = jam + 10
end

Clicker.MouseClick:Connect(Clicked)

The reasoning is because you're setting the "jam" value to equal whatever it is at first. That will cause the value to ALWAYS = 5, for example. When the function is called, the variable isn't updated, and is instead only created and updated once. I hope I explained it ok.

The fix makes it so that the "jam" variable will update every time the function is called, simply by moving the variable to inside of that function.

0
sorry for the late response boopahead08 0 — 3y
0
sorry for the late response. When your script was applied It didn't change the variable nor the speed, though thanks for trying boopahead08 0 — 3y
0
oh wait im just dumb sorry you're right boopahead08 0 — 3y
Ad

Answer this question