Advertisement
Previized

BONUS #2

Dec 24th, 2020
1,327
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.83 KB | None | 0 0
  1. local ModelName = 'NPC' -- The name of the model to be moved
  2.  
  3. local ModelToMove = workspace:FindFirstChild(ModelName) -- Model must be in Workspace for this to work
  4. local CFrameParts = ModelToMove.CFrameParts
  5.  
  6. local Main = ModelToMove.Main
  7. local CFP1 = CFrameParts.CFramePart1 -- CFramePart1 (Will be used for getting the Original Position)
  8. local CFP2 = CFrameParts.CFramePart2 -- CFramePart2 (Getting the position to where the model will move to)
  9.  
  10. local OrignialPosition = CFP1.CFrame -- Here we get the CFrame
  11. local SetPosition = CFP2.CFrame -- Gets CFrame ("Position") of the block where the model will move which is "CFramePart2"
  12.  
  13. CFP1:Destroy() -- We get rid of them because they are useless now that we have the CFrame for them!
  14. CFP2:Destroy()
  15.  
  16.  
  17. ModelToMove.PrimaryPart = Main --[[ Sets the model's PrimaryPart so we can use :SetPrimaryPartCFrame() which will be ..
  18.                                     helpful for moving the model as a whole ]]
  19.  
  20. local Machine = workspace.Machine
  21. local Board = Machine.Board
  22. local CountdownPart = Board.CountdownPart
  23.  
  24. CountdownPart.SurfaceGui.TextLabel.Text = 'Ready'
  25. local function CountDown(InProcess)
  26.     if InProcess == true then
  27.         for i = 10,0,-1 do
  28.             CountdownPart.SurfaceGui.TextLabel.Text = 'Can use in: ' ..i
  29.             wait(1)
  30.         end
  31.         CountdownPart.SurfaceGui.TextLabel.Text = 'Ready'
  32.     end
  33. end
  34.  
  35. local Touched = false -- Debounce
  36. script.Parent.Touched:Connect(function(hit)
  37.     if hit.Parent:FindFirstChild('Humanoid') then
  38.         if Touched == false then
  39.             Touched = true
  40.            
  41.             ModelToMove:SetPrimaryPartCFrame(SetPosition) --[[ The code is saying; when you have touched the block, it will ..
  42.                                                            move and never work again in this server because of the debounce]]
  43.            
  44.             CountDown(true)
  45.             ModelToMove:SetPrimaryPartCFrame(OrignialPosition) -- Moves to original position
  46.             Touched = false
  47.         end
  48.     end
  49. end)
  50.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement