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

How would i make a bodyforce have a on/off switch(onclick)?

Asked by 9 years ago

trying to have it lift things up when I click on the on button and off when clicked off? REALLY NEW TO SCRIPTING):

1 answer

Log in to vote
0
Answered by 9 years ago

Well, considering that it doesn't have an enabled option I would recommend doing this

local OffButton = script.Parent; --Variable to reference the button 
local partWithForce = game.Workspace.WhereEverItIs; --Replace with where you part actually is
OffButton.ClickDetector.MouseClick:connect(function()
    partWithForce.BodyForce.force = Vector3.new(0,0,0); --This will turn the force off
end)

And if you want to turn it back on

local OnButton = script.Parent; --Wherever your actual button is
local partWithForce = game.Workspace.WhereEverItIs;
OnButton.ClickDetector.MouseClick:connect(function()
    local force = Vector3.new(PUT, NUMBERS, HERE); --Replace with your force
    partWithForce.BodyForce.force = force--This will turn the force back on
end)
0
my bodyforce brick is called up and the on and off buttons are just 1 and 2 so yeaa if that helps ags5321 0 — 9y
0
In order for a script to do something to anything, if has to know WHAT to work on. If I put a brick inside my workspace called "Hello", than the only way I could make a script do something to it would be game.Workspace.Hello Does that make sense? DewnOracle 115 — 9y
0
The local variable called "partWithForce" has to have an actual brick associated with it. If i wanted to use my hello brick because the body force was inside it, I would say local partWithForce = game.Workspace.Hello DewnOracle 115 — 9y
0
Yup DewnOracle 115 — 9y
View all comments (9 more)
0
alrigh i have that and nothing ags5321 0 — 9y
0
you do the script and see if it work for you ags5321 0 — 9y
0
Alright, I see what I did wrong. I was trying to edit the force by saying partWithForce.BodyForce but I needed to add .force to the end of that DewnOracle 115 — 9y
0
Remember, the BodyForce requires ridiculously huge numbers to do stuff. DewnOracle 115 — 9y
0
yeaaa i got 1575 in there ags5321 0 — 9y
0
alright got it but im gonna need it to be grouped ags5321 0 — 9y
0
never mind man i gt it thanks for te help ags5321 0 — 9y
0
No problem! Can you accept my answer if it helped you? DewnOracle 115 — 9y
0
ohh yaa ags5321 0 — 9y
Ad

Answer this question