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

Can someone help me with the On/Off button on a minecart that will make the minecart move?

Asked by 3 years ago

Hello can someone maybe help with this,

I have a minecart but as u know you can turn it off or on, But i want it as if you turn the cart on you cant turn it off anymore.

Does someone know how this works?

function chng() script.Parent.Parent.CarOn.Value = not script.Parent.Parent.CarOn.Value if script.Parent.Parent.CarOn.Value == false then script.Parent.BrickColor = BrickColor.new(21) else script.Parent.BrickColor = BrickColor.new(28) end end

script.Parent.Click.MouseClick:connect(chng)

This is the code for the minecart button that will let it move

1 answer

Log in to vote
0
Answered by 3 years ago

What you're doing is changing the CarOn BoolValue to it's opposite value. Everytime someone clicks the button and for example, the car is on, it will change to off, if the player clicks it again, it will change to on. There's your code, hope it helps u understand

function chng() 
    local CarOn = script.Parent.Parent.CarOn

    --If the minecart is on, then don't do nothing
    if CarOn.Value == true then 
        return
    elseif CarOn.Value == false then --But if the minecart is off, then set the car on
        CarOn.Value = true  

        --Here you can script what you want to do when it turn on
    end



end

script.Parent.Click.MouseClick:connect(chng)
0
Thank u! it works! =D souf1000 6 — 3y
Ad

Answer this question