EmeraldIT

Light Ring V2

Aug 9th, 2025
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. -- SETTINGS
  2. local numParts = 8 -- number of parts
  3. local partDepth = 4 -- initial Z size
  4. local partHeight = 1
  5. local travelDistance = 50 -- studs to move forward
  6. local animationTime = 3 -- seconds to complete movement
  7. local lightRange = 20
  8. local lightBrightness = 2
  9.  
  10. -- SETUP
  11. local model = script.Parent
  12. for _, obj in ipairs(model:GetChildren()) do
  13. if obj:IsA("BasePart") then
  14. obj:Destroy()
  15. end
  16. end
  17.  
  18. local parts = {}
  19. for i = 0, numParts - 1 do
  20. local angle = i * (2 * math.pi / numParts)
  21.  
  22. local part = Instance.new("Part")
  23. part.Anchored = true
  24. part.CanCollide = false
  25. part.Size = Vector3.new(0, partHeight, partDepth) -- width will change
  26. part.CFrame = CFrame.new(0, 0, 0) * CFrame.Angles(0, -angle, 0)
  27. part.Parent = model
  28.  
  29. local light = Instance.new("SurfaceLight")
  30. light.Face = Enum.NormalId.Front
  31. light.Angle = 360 / numParts
  32. light.Range = lightRange
  33. light.Brightness = lightBrightness
  34. light.Parent = part
  35.  
  36. table.insert(parts, {
  37. part = part,
  38. angle = angle
  39. })
  40. end
  41.  
  42. -- ANIMATION
  43. local runService = game:GetService("RunService")
  44. local startTime = tick()
  45.  
  46. local connection
  47. connection = runService.Heartbeat:Connect(function()
  48. local elapsed = tick() - startTime
  49. local alpha = math.min(elapsed / animationTime, 1)
  50. local r = alpha * travelDistance
  51.  
  52. for _, data in ipairs(parts) do
  53. -- Calculate width so edges touch
  54. local width = 2 * r * math.sin(math.pi / numParts)
  55. if width < 0.05 then width = 0.05 end -- prevent zero size
  56.  
  57. -- Update size
  58. data.part.Size = Vector3.new(width, partHeight, partDepth)
  59.  
  60. -- Position outward along local Z axis
  61. local pos = CFrame.new(0, 0, r) -- move along local Z
  62. data.part.CFrame = CFrame.Angles(0, -data.angle, 0) * pos * CFrame.Angles(0, -data.angle, 0)
  63. end
  64.  
  65. if alpha >= 1 then
  66. connection:Disconnect()
  67. end
  68. end)
Advertisement
Add Comment
Please, Sign In to add comment