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

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

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

✓ Accepted answer

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)

1 comment

0

Thank u! it works! =D

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