Advertisement
RoScripter

Asteroid Script

Mar 7th, 2020
1,134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.49 KB | None | 0 0
  1. local tweenService = game:GetService("TweenService")
  2. local tweenTime = 2
  3. local info = TweenInfo.new(tweenTime)
  4. local asteroidHeight = 150
  5.  
  6. local function tweenModel(model, CF)
  7.     local CFrameValue = Instance.new("CFrameValue")
  8.     CFrameValue.Value = model:GetPrimaryPartCFrame()
  9.  
  10.     CFrameValue:GetPropertyChangedSignal("Value"):Connect(function()
  11.         model:SetPrimaryPartCFrame(CFrameValue.Value)
  12.     end)
  13.    
  14.     local tween = tweenService:Create(CFrameValue, info, {Value = CF})
  15.     tween:Play()
  16.    
  17.     tween.Completed:Connect(function()
  18.         CFrameValue:Destroy()
  19.     end)
  20. end
  21.  
  22. function animateAsteroid()
  23.     local baseplatePosition = game.Workspace.Baseplate.Position
  24.     local baseplateSize = game.Workspace.Baseplate.Size
  25.    
  26.     local randomXCframe = math.random(baseplatePosition.X - baseplateSize.X /2, baseplatePosition.X + baseplateSize.X / 2)
  27.     local randomZCframe = math.random(baseplatePosition.Z - baseplateSize.Z /2, baseplatePosition.Z + baseplateSize.Z / 2)
  28.    
  29.     local Asteroid = script.Asteroid:Clone()
  30.     Asteroid.Parent = game.Workspace
  31.     Asteroid:SetPrimaryPartCFrame(CFrame.new(randomXCframe, asteroidHeight, randomZCframe))
  32.    
  33.     local xTweenTo = math.random(baseplatePosition.X - baseplateSize.X /2, baseplatePosition.X + baseplateSize.X / 2)
  34.     local zTweenTo = math.random(baseplatePosition.Z - baseplateSize.Z /2, baseplatePosition.Z + baseplateSize.Z / 2)
  35.    
  36.     tweenModel(Asteroid, CFrame.new(xTweenTo, baseplatePosition.Y - 10, zTweenTo))
  37.     wait(tweenTime)
  38.     Asteroid:Destroy()
  39. end
  40.  
  41. wait(1)
  42. animateAsteroid()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement