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: Help with a elevator script

Previous Thread :: Next Thread 
cooldrewbie is not online. cooldrewbie
Joined: 26 Jun 2010
Total Posts: 2498
23 Apr 2016 11:56 AM
So im making an elevator like the one in flood escape, where its timed and if you want to play you hop on it and it takes you down. This is what I have but it doesnt go down really well... Anyone have ideas on how to fix this or a way to make it better?

waittime = 2
speed = 20

d = 1
running = false
elevator = script.Parent.Elevator
elevator.BodyGyro.cframe = elevator.CFrame
elevator.BodyPosition.position = elevator.Position
bv = elevator.BodyVelocity
levels = { }
l = script.Parent.Levels:GetChildren()

if #l ~= 0 then
for i = 1, #l do
if l[i].className == "Part" then
table.insert(levels,l[i].Position.y)
end
end
else
error("Not enough markers",0)
end

table.sort(levels)
script.Parent.Levels.Parent = nil -- Now that we have the height for each level, the markers are pretty much useless.

elevator.BodyPosition.position = Vector3.new(elevator.Position.x,levels[1],elevator.Position.z)
while true do
if math.sqrt(((levels[1]-elevator.Position.y)^2)) < 1 then break end
wait()
end
bv.maxForce = Vector3.new(0,9.9e+005,0)
wait(waittime)

elevator.Anchored = false -- ready to go, unlock platform

while true do
wait()
for i = 2,#levels do
if running == false then
bv.velocity = Vector3.new(0,speed,0)
running = true
end
while true do
wait()
if elevator.Position.y >= levels[i] then
bv.velocity = Vector3.new(0,0,0)
elevator.BodyPosition.position = elevator.Position
running=false
wait(waittime)
break
end
end
end
for i = #levels-1,1,-1 do
if running == false then
bv.velocity = Vector3.new(0,-speed,0)
running = true
end
while true do
wait()
if elevator.Position.y <= levels[i] then
bv.velocity = Vector3.new(0,0,0)
elevator.BodyPosition.position = elevator.Position
running=false
wait(waittime)
break
end
end
end
end
Report Abuse
Lord_Narwhal is not online. Lord_Narwhal
Joined: 05 May 2012
Total Posts: 3242
23 Apr 2016 12:04 PM
this is the perfect moment to use :lerp

it flawlessly will move a brick from one position to the next at a custom speed


#Code print("Add 13,000 posts")
Report Abuse
cooldrewbie is not online. cooldrewbie
Joined: 26 Jun 2010
Total Posts: 2498
23 Apr 2016 12:07 PM
Ill look into it!
Thank you narwhal
Report Abuse
Lord_Narwhal is not online. Lord_Narwhal
Joined: 05 May 2012
Total Posts: 3242
23 Apr 2016 12:09 PM
here is how I would use lerp on the elevator


local startingPos = game.Workspace.Elevator.Position
local endingPos = game.Workspace.Elevator.Position + Vector3.new(0,-10,0)
local elevator = game.Workspace.Elevator

for ratio = 0,speed,0.1 do
local newPosition = startingPos:lerp(endingPos, ratio/speed)
elevator.Position = newPosition
wait()
end

the higher the speed, the slower it will move


#Code print("Add 13,000 posts")
Report Abuse
cooldrewbie is not online. cooldrewbie
Joined: 26 Jun 2010
Total Posts: 2498
23 Apr 2016 12:16 PM
So then pretty much all I would have to do is define speed and change the coordinates to my liking's?
Report Abuse
Lord_Narwhal is not online. Lord_Narwhal
Joined: 05 May 2012
Total Posts: 3242
23 Apr 2016 12:17 PM
yes, and it will move smoothly


#Code print("Add 13,000 posts")
Report Abuse
cooldrewbie is not online. cooldrewbie
Joined: 26 Jun 2010
Total Posts: 2498
23 Apr 2016 12:18 PM
sweet thanks!
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