Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local RunService = game:GetService("RunService")
- local Players = game:GetService("Players")
- local platform = workspace:WaitForChild("MagicDisc")
- local raycastDistance = 5
- local previousPosition = platform.Position
- local function setupVectorForce(character)
- local hrp = character:FindFirstChild("HumanoidRootPart")
- if not hrp then return end
- if not hrp:FindFirstChild("PlatformAttachment") then
- local attachment = Instance.new("Attachment")
- attachment.Name = "PlatformAttachment"
- attachment.Parent = hrp
- local force = Instance.new("VectorForce")
- force.Name = "PlatformForce"
- force.Attachment0 = attachment
- force.RelativeTo = Enum.ActuatorRelativeTo.World
- force.ApplyAtCenterOfMass = true
- force.Force = Vector3.zero
- force.Parent = hrp
- end
- end
- local function removeVectorForce(character)
- local hrp = character:FindFirstChild("HumanoidRootPart")
- if not hrp then return end
- local force = hrp:FindFirstChild("PlatformForce")
- local attachment = hrp:FindFirstChild("PlatformAttachment")
- if force then force:Destroy() end
- if attachment then attachment:Destroy() end
- end
- RunService.Heartbeat:Connect(function(dt)
- if dt == 0 then return end -- Prevent division by zero
- local currentPosition = platform.Position
- local platformVelocity = (currentPosition - previousPosition) / dt
- previousPosition = currentPosition
- for _, player in ipairs(Players:GetPlayers()) do
- local character = player.Character
- if not character then continue end
- local hrp = character:FindFirstChild("HumanoidRootPart")
- if not hrp then continue end
- -- Setup VectorForce if needed
- setupVectorForce(character)
- -- Raycast down to check if player is standing on the platform
- local rayOrigin = hrp.Position
- local rayDirection = Vector3.new(0, -raycastDistance, 0)
- local params = RaycastParams.new()
- params.FilterDescendantsInstances = {character}
- params.FilterType = Enum.RaycastFilterType.Blacklist
- local result = workspace:Raycast(rayOrigin, rayDirection, params)
- local onPlatform = result and result.Instance and result.Instance:IsDescendantOf(platform)
- local force = hrp:FindFirstChild("PlatformForce")
- if force then
- if onPlatform then
- -- Apply force = velocity * mass / dt
- local mass = character:GetMass()
- force.Force = platformVelocity * mass / dt
- else
- force.Force = Vector3.zero
- end
- end
- end
- end)
- -- Optional: Cleanup force when player leaves
- Players.PlayerRemoving:Connect(function(player)
- local char = player.Character
- if char then removeVectorForce(char) end
- end)
- -- Optional: Set up for players who respawn
- Players.PlayerAdded:Connect(function(player)
- player.CharacterAdded:Connect(function(character)
- task.wait(1) -- Let character load
- setupVectorForce(character)
- end)
- end)
Advertisement
Add Comment
Please, Sign In to add comment