Advertisement
Plexplayer118

SS RBXL Class Lesson 1

Oct 14th, 2019
364
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. --Code for lesson 1 of Matt's Roblox Coding Course on SS
  2. --Copy-paste this into your script!
  3.  
  4. local spawner = script.Parent
  5. local tool = nil
  6. local region = Region3.new(Vector3.new(spawner.Position.X - spawner.Size.X/2, spawner.Position.Y + spawner.Size.Y/2, spawner.Position.Z - spawner.Size.Z/2),
  7. Vector3.new(spawner.Position.X + spawner.Size.X/2, spawner.Position.Y + 4, spawner.Position.Z + spawner.Size.Z/2))
  8. local parts = game.Workspace:FindPartsInRegion3(region)
  9. for _, part in pairs(parts) do
  10. if part and part.Parent and part.Parent:IsA("Tool") then
  11. tool = part.Parent
  12. break
  13. end
  14. end
  15.  
  16. local configTable = spawner.Configurations
  17. local configs = {}
  18. local function loadConfig(configName, defaultValue)
  19. if configTable:FindFirstChild(configName) then
  20. configs[configName] = configTable:FindFirstChild(configName).Value
  21. else
  22. configs[configName] = defaultValue
  23. end
  24. end
  25.  
  26. loadConfig("SpawnCooldown", 5)
  27.  
  28. if tool then
  29. tool.Parent = game.ServerStorage
  30.  
  31. while true do
  32. -- put tool on pad
  33. local toolCopy = tool:Clone()
  34. local handle = toolCopy:FindFirstChild("Handle")
  35. toolCopy.Parent = game.Workspace
  36. local toolOnPad = true
  37. local parentConnection
  38. parentConnection = toolCopy.AncestryChanged:connect(function()
  39. if handle then handle.Anchored = false end
  40. toolOnPad = false
  41. parentConnection:disconnect()
  42. end)
  43. if handle then
  44. handle.CFrame = (spawner.CFrame + Vector3.new(0,handle.Size.Z/2 + 1,0)) * CFrame.Angles(-math.pi/2,0,0)
  45. handle.Anchored = true
  46. end
  47. -- wait for tool to be removed
  48. while toolOnPad do
  49. if handle then
  50. handle.CFrame = handle.CFrame * CFrame.Angles(0,0,math.pi/60)
  51. end
  52. wait()
  53. end
  54.  
  55. -- wait for cooldown
  56. wait(configs["SpawnCooldown"])
  57. end
  58.  
  59. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement