generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Is this correct use of a function?

Previous Thread :: Next Thread 
MasterLogical is not online. MasterLogical
Joined: 14 Jun 2015
Total Posts: 379
17 Jun 2015 05:00 PM
Should I use a onClick() if I have a GUI button that turns on a boat basically unanchors the base of the boat.

Would I use function onClick()
base.Anchor = false
end

Here's what I have in the script so far tho

engine = script.Parent.Parent
button = script.Parent
base = script.Parent.Parent.Parent.Parent.Base


Also what do I use to turn off the boat? (anchor the base)


Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
17 Jun 2015 05:03 PM
local player = game.Players.LocalPlayer
local boat = workspace[player.Name.."Boat"]
local engine = boat.Engine
local base = boat.Base

gui.MouseButton1Click:connect(function()
base.Anchored = false
end)
Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
17 Jun 2015 05:04 PM
btw

gui = script.Parent
Report Abuse
helicopter35 is not online. helicopter35
Joined: 25 Oct 2010
Total Posts: 1225
17 Jun 2015 05:04 PM
--[[For this one, make sure you have a weld to keep the boat together when it is not anchored. Unless, it will fall apart]]--

button1 = script.Parent

button1.ClickDetector.MouseClick:connect(function()
base.Anchored = false
end)

--Stop the boat

button2 = script.Parent

button2.ClickDetector.MouseClick:connect(function()
base.Anchored = true
end)


--MAKE SURE THERE IS A CLICKDETECTOR IN BOTH BUTTONS.
Report Abuse
MasterLogical is not online. MasterLogical
Joined: 14 Jun 2015
Total Posts: 379
17 Jun 2015 05:07 PM
They don't work
Report Abuse
MasterLogical is not online. MasterLogical
Joined: 14 Jun 2015
Total Posts: 379
17 Jun 2015 05:32 PM
I don't want a button brick, I want a gui button that works to anchor and unanchor the base
Report Abuse
MasterLogical is not online. MasterLogical
Joined: 14 Jun 2015
Total Posts: 379
17 Jun 2015 06:09 PM
I got it!

boat = game.Workspace.Boat
button = script.Parent
enginecontrol = script.Parent.Parent
engine = boat.Base

function onClick(GUI)
engine.Anchored = false
end

script.Parent.MouseButton1Click:connect(onClick)


There's the script, but now how do I make it where if you click the button once more the engine anchors?
Report Abuse
MasterLogical is not online. MasterLogical
Joined: 14 Jun 2015
Total Posts: 379
17 Jun 2015 06:11 PM
Bump
Report Abuse
Lineout is not online. Lineout
Joined: 06 Nov 2012
Total Posts: 684
17 Jun 2015 06:12 PM
Debounce
Report Abuse
MasterLogical is not online. MasterLogical
Joined: 14 Jun 2015
Total Posts: 379
17 Jun 2015 06:13 PM
How do I do that?
Report Abuse
BusyCityGuy is not online. BusyCityGuy
Joined: 17 Aug 2012
Total Posts: 2144
17 Jun 2015 06:13 PM
boat = workspace.Boat
engine = boat.Base
button = script.Parent
engineControl = button.Parent

button.MouseButton1Click:connect(function()
engine.Anchored = not engine.Anchored
end)

Not sure why you need to use variables for everything like that but this should work.

-The [Guy]
Report Abuse
MasterLogical is not online. MasterLogical
Joined: 14 Jun 2015
Total Posts: 379
17 Jun 2015 06:14 PM
I'm gonna add more things to the script
Report Abuse
MasterLogical is not online. MasterLogical
Joined: 14 Jun 2015
Total Posts: 379
17 Jun 2015 06:15 PM
It Works thanks theguy!
Report Abuse
Lineout is not online. Lineout
Joined: 06 Nov 2012
Total Posts: 684
17 Jun 2015 06:16 PM
local debounce = false

if debounce == false then debounce = true
---Anchor
elseif debounce == true then debounce = false
--- Un anchor
end
Report Abuse
BusyCityGuy is not online. BusyCityGuy
Joined: 17 Aug 2012
Total Posts: 2144
17 Jun 2015 06:22 PM
No problem. Simple solutions for the win. :P If you don't need the variables, consider these simple 3 lines to do everything.

script.Parent.MouseButton1Click:connect(function()
boat.Base.Anchored = not boat.Base.Anchored
end)

-The [Guy]
Report Abuse
BusyCityGuy is not online. BusyCityGuy
Joined: 17 Aug 2012
Total Posts: 2144
17 Jun 2015 06:24 PM
Oh my gosh, sorry, messed that up. I meant this:

script.Parent.MouseButton1Click:connect(function()
workspace.Boat.Base.Anchored = not workspace.Boat.Base.Anchored
end)

-The [Guy]
Report Abuse
Lineout is not online. Lineout
Joined: 06 Nov 2012
Total Posts: 684
17 Jun 2015 06:24 PM
"Part.Anchored = not Part.Anchored"

Where has that been my whole life! Thanks.
Report Abuse
MasterLogical is not online. MasterLogical
Joined: 14 Jun 2015
Total Posts: 379
17 Jun 2015 06:26 PM
I been playing ROBLOX since 2010 and i'm barely getting in to scripting XD!
Report Abuse
BusyCityGuy is not online. BusyCityGuy
Joined: 17 Aug 2012
Total Posts: 2144
17 Jun 2015 06:26 PM
Haha yes it is a very nice bit of logic to use. :)

-The [Guy]
Report Abuse
MasterLogical is not online. MasterLogical
Joined: 14 Jun 2015
Total Posts: 379
17 Jun 2015 11:42 PM
engine.Anchored = not engine.Anchored

Can someone explain that line to me? I don't just want to copy and paste I want to understand it too.
Report Abuse
SolePlayer is not online. SolePlayer
Joined: 06 May 2012
Total Posts: 481
18 Jun 2015 12:17 AM
If the engine is anchored it makes it unanchored and vice versa.
Report Abuse
BusyCityGuy is not online. BusyCityGuy
Joined: 17 Aug 2012
Total Posts: 2144
19 Jun 2015 11:44 AM
"not" just makes it opposite. So if the value is true, "not true" will logically mean false. Same for "not false", which means true.

So if I said

thing.Anchored = not true

I believe that should make it false. But since you are setting it to

thing.Anchored = not thing.Anchored

then it will be whatever it wasn't.

-The [Guy]
Report Abuse
MasterLogical is not online. MasterLogical
Joined: 14 Jun 2015
Total Posts: 379
19 Jun 2015 11:49 AM
Thanks, I used it to Make a boat it canme in handy in this GUI I made, check it out
http://www.roblox.com/Player-Settings-GUI-V1-item?id=260109559

Or you can use it at my game just press G
Report Abuse
BusyCityGuy is not online. BusyCityGuy
Joined: 17 Aug 2012
Total Posts: 2144
19 Jun 2015 11:58 AM
I used the same concept of anchoring a boat for this little thing I was experimenting with.

http://www.roblox.com/games/187814397/Boat-Wars-Project-just-started

-The [Guy]
Report Abuse
MasterLogical is not online. MasterLogical
Joined: 14 Jun 2015
Total Posts: 379
19 Jun 2015 12:04 PM
I'm on my phone lol
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image