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

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

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

✓ Accepted answer

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)

13 comments

0

my bodyforce brick is called up and the on and off buttons are just 1 and 2 so yeaa if that helps

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?

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

0

Yup

0

alrigh i have that and nothing

0

you do the script and see if it work for you

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

0

Remember, the BodyForce requires ridiculously huge numbers to do stuff.

0

yeaaa i got 1575 in there

0

alright got it but im gonna need it to be grouped

0

never mind man i gt it thanks for te help

0

No problem! Can you accept my answer if it helped you?

0

ohh yaa

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