Advertisement
Previized

BONUS #1

Dec 24th, 2020
1,348
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.43 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.  
  21. local Touched = false -- Debounce
  22. script.Parent.Touched:Connect(function(hit)
  23.     if hit.Parent:FindFirstChild('Humanoid') then
  24.         if Touched == false then
  25.             Touched = true
  26.            
  27.             ModelToMove:SetPrimaryPartCFrame(SetPosition) --[[ The code is saying; when you have touched the block, it will ..
  28.                                                            move and never work again in this server because of the debounce]]
  29.             wait(5)
  30.             ModelToMove:SetPrimaryPartCFrame(OrignialPosition) -- Moves to original position
  31.             Touched = false
  32.         end
  33.     end
  34. end)
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement