|
| 14 Jun 2012 06:20 PM |
--The other day I tried to learn scripting from the Roblox Wiki. For the past two days, I have been working on a script, a very simple one that a professional could do in about a minute. It goes like this --
-local brick = Workspace.Part
function onTouch(part)
brick.Anchored = false wait(3) brick.Anchored = true wait(0.5) Teleport = -12, 5.8, -60
end
brick.Touched:connect(onTouch)
--How I would like it--
--You touch the brick --The brick falls --After 3 seconds, the brick anchors itself --After half a second of being anchored it teleports back to its original position
--I have tested this and everything in this works except for the teleportation part. What is the command for that and is it even possible? |
|
|
| Report Abuse |
|
|
|
| 14 Jun 2012 06:23 PM |
| Please tell me if this is not possible. |
|
|
| Report Abuse |
|
|
|
| 14 Jun 2012 06:25 PM |
| Or at least say IDK if YDK. |
|
|
| Report Abuse |
|
|
killjoy37
|
  |
| Joined: 27 Aug 2008 |
| Total Posts: 2821 |
|
|
| 14 Jun 2012 06:26 PM |
you almost got it. the teleport = ... line, change to brick.CFrame = originalposition and make originalposition a variable at the very top of the script right below the local brick = ... line, and make it say originalposition = brick.CFrame, like this:
local brick = Workspace.Part originalposition = brick.CFrame
function onTouch(part)
brick.Anchored = false wait(3) brick.Anchored = true wait(0.5) brick.CFrame = originalposition
end
brick.Touched:connect(onTouch)
Let me know if it works
|
|
|
| Report Abuse |
|
|
|
| 14 Jun 2012 06:30 PM |
| It works! Thanks for helping me out. I really appreciate it. |
|
|
| Report Abuse |
|
|
|
| 14 Jun 2012 06:47 PM |
Johnny,
I don't know, but I sympathise with you. I will add my 2 cents worth. You seem like u have probably used other laguages before..... If not go research Basic Programming on the Net. Most concpts r the same.
You should not be writing scripts from scratch. Take a model u like and edit it.
local brick = Workspace.Part -- This will look for any old part in Workspace, called Part. It won't look in Models for a part. It may not be the "Part" u r thinking about.
print(brick, brick.Name, brick.ClassName, brick.Parent) -- Open View>Output. Put print statements every other line or u will never be able to follow what is going on.
function onTouch(part)
print (part) -- this should print about 100 times, because u have cvalled this function with an interupt (In Roblox called, "Events"), and u took-out the "De-bounce", because u didn't know why it was there.
brick.Anchored = false wait(3) brick.Anchored = true wait(0.5) Teleport = -12, 5.8, -60 -- u must open output, Johnny. The computer WILL tell you there are syntax (spelling) errors here.
--You may want: local Teleport = Vector3.new(-12, 5.8, -60) -- New, temporary variable called, Teleport, will equal a data structure called Vector3, which is three, real numbers.
brick.Position = Teleport -- Make the Position Property of brick equal to that V#.
end -- function onTouch
brick.Touched:connect(onTouch) -- this is the interupt, which fires (calls onTouch), AS LONG as ANYTHING is touching it, and will not stop calling onTouch, until you take your foot off it.
(end of part 1)
|
|
|
| Report Abuse |
|
|
|
| 14 Jun 2012 06:55 PM |
Better: (This may not work, just coding on the fly here...)
local brick = Workspace.PartThisOne -- Have this part have a unique name local Teleport = brick.Position -- this way we don't have to know here the brick is, or deal with any actual numbers.
(Sorry; gotta go....)
function onTouch(part)
brick.Anchored = false wait(3) brick.Anchored = true wait(0.5) Teleport = -12, 5.8, -60
end
brick.Touched:connect(onTouch)
|
|
|
| Report Abuse |
|
|
killjoy37
|
  |
| Joined: 27 Aug 2008 |
| Total Posts: 2821 |
|
|
| 14 Jun 2012 07:36 PM |
| Why the heck did you tell him to not write scripts from scratch? How will he learn? Keep at it johnny. |
|
|
| Report Abuse |
|
|
|
| 14 Jun 2012 07:51 PM |
I'm back.
Anyway make your model in workspace then put script & APart (Name is "APart") in it like this
Workspace ..model ....script ....APart
Now we know exactly how to get acces to that part:
local brick = script.Parent.APart -- APart is scripts brother (It has the sae Parent as us). If we refer to everything by its relation to where-ever "script" is, then we never have to know where, (or how deep in models) a part actualy is...
local Teleport = brick.Position -- get its starting position - at the start. Stuff it in this Vector3 called Teleport. Yes Teleport takes the Type, and the Contents of Brick.Position
local closed = false -- The gate is "Open". (This is also refered to as a debounce). It is just a tool we made-up for our program.
function onTouch(part) -- This defines a function, AND a local variable called part, which was passed by Touched connect, (but we don't care WHO or what touched it).
if not closed then -- if the gate is not closed then --if closed == false then -- same thing
closed = true -- close it, cause we r in here, and only one program at a time in here...
brick.Anchored = false -- do your thing wait(3) brick.Anchored = true wait(0.5) brick.Position = Teleport -- re-stuff position.
closed = false -- re-open the gate, 'cause we r leaving. end -- function -- leave
brick.Touched:connect(onTouch) -- set-up
Did, I mention that this will not work. It is just a rough draft...
GL, Brian
|
|
|
| Report Abuse |
|
|
|
| 14 Jun 2012 08:00 PM |
lSorry,
And Open View>Output and add prints so that you can debug it, and make it work....
ocal brick = script.Parent.APart -- APart is scripts brother (It has the sae Parent as us). If we refer to everything by its relation to where-ever "script" is, then we never have to know where, (or how deep in models) a part actualy is...
print(brick)
local Teleport = brick.Position -- get its starting position - at the start. Stuff it in this Vector3 called Teleport. Yes Teleport takes the Type, and the Contents of Brick.Position
print("Position :", Brick.Position)
local closed = false -- The gate is "Open". (This is also refered to as a debounce). It is just a tool we made-up for our program.
function onTouch(part) -- This defines a function, AND a local variable called part, which was passed by Touched connect, (but we don't care WHO or what touched it).
print(part, closed)
if not closed then -- if the gate is not closed then --if closed == false then -- same thing
closed = true -- close it, cause we r in here, and only one program at a time in here...
print("Anchored? ", Anchored = true) brick.Anchored = false -- do your thing print("Anchored? ", Anchored = true)
wait(3)
brick.Anchored = true print("Anchored? ", Anchored = true)
wait(0.5) brick.Position = Teleport -- re-stuff position. print(brick.Position) closed = false -- re-open the gate, 'cause we r leaving. end -- function -- leave
brick.Touched:connect(onTouch) -- set-up
Did, I mention that this will not work. It is just a rough draft...
GL, Brian
|
|
|
| Report Abuse |
|
|
|
| 16 Jun 2012 09:09 AM |
| I had the answer on the fourth reply... no need to help me anymore but thanks for trying to help! |
|
|
| Report Abuse |
|
|