EmeraldIT

Untitled

Jul 7th, 2025
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.78 KB | None | 0 0
  1. local RunService = game:GetService("RunService")
  2. local Players = game:GetService("Players")
  3.  
  4. local platform = workspace:WaitForChild("MagicDisc")
  5. local raycastDistance = 5
  6. local previousPosition = platform.Position
  7.  
  8. local function setupVectorForce(character)
  9. local hrp = character:FindFirstChild("HumanoidRootPart")
  10. if not hrp then return end
  11.  
  12. if not hrp:FindFirstChild("PlatformAttachment") then
  13. local attachment = Instance.new("Attachment")
  14. attachment.Name = "PlatformAttachment"
  15. attachment.Parent = hrp
  16.  
  17. local force = Instance.new("VectorForce")
  18. force.Name = "PlatformForce"
  19. force.Attachment0 = attachment
  20. force.RelativeTo = Enum.ActuatorRelativeTo.World
  21. force.ApplyAtCenterOfMass = true
  22. force.Force = Vector3.zero
  23. force.Parent = hrp
  24. end
  25. end
  26.  
  27. local function removeVectorForce(character)
  28. local hrp = character:FindFirstChild("HumanoidRootPart")
  29. if not hrp then return end
  30. local force = hrp:FindFirstChild("PlatformForce")
  31. local attachment = hrp:FindFirstChild("PlatformAttachment")
  32. if force then force:Destroy() end
  33. if attachment then attachment:Destroy() end
  34. end
  35.  
  36. RunService.Heartbeat:Connect(function(dt)
  37. if dt == 0 then return end -- Prevent division by zero
  38. local currentPosition = platform.Position
  39. local platformVelocity = (currentPosition - previousPosition) / dt
  40. previousPosition = currentPosition
  41.  
  42. for _, player in ipairs(Players:GetPlayers()) do
  43. local character = player.Character
  44. if not character then continue end
  45.  
  46. local hrp = character:FindFirstChild("HumanoidRootPart")
  47. if not hrp then continue end
  48.  
  49. -- Setup VectorForce if needed
  50. setupVectorForce(character)
  51.  
  52. -- Raycast down to check if player is standing on the platform
  53. local rayOrigin = hrp.Position
  54. local rayDirection = Vector3.new(0, -raycastDistance, 0)
  55.  
  56. local params = RaycastParams.new()
  57. params.FilterDescendantsInstances = {character}
  58. params.FilterType = Enum.RaycastFilterType.Blacklist
  59.  
  60. local result = workspace:Raycast(rayOrigin, rayDirection, params)
  61.  
  62. local onPlatform = result and result.Instance and result.Instance:IsDescendantOf(platform)
  63.  
  64. local force = hrp:FindFirstChild("PlatformForce")
  65. if force then
  66. if onPlatform then
  67. -- Apply force = velocity * mass / dt
  68. local mass = character:GetMass()
  69. force.Force = platformVelocity * mass / dt
  70. else
  71. force.Force = Vector3.zero
  72. end
  73. end
  74. end
  75. end)
  76.  
  77. -- Optional: Cleanup force when player leaves
  78. Players.PlayerRemoving:Connect(function(player)
  79. local char = player.Character
  80. if char then removeVectorForce(char) end
  81. end)
  82.  
  83. -- Optional: Set up for players who respawn
  84. Players.PlayerAdded:Connect(function(player)
  85. player.CharacterAdded:Connect(function(character)
  86. task.wait(1) -- Let character load
  87. setupVectorForce(character)
  88. end)
  89. end)
Advertisement
Add Comment
Please, Sign In to add comment