Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

I can't ride on a moving platform, how do I fix this?

Asked by 3 years ago
Edited 3 years ago

I am making a horizontal obby game and I'm trying to make a moving platform that can reach more than 2 position points. However, as I tested and stand on the moving platform, I can't ride and I have to move manually.

I have added the BodyMovers and looked at the forums, and still... no luck.

Here's the footage: https://youtu.be/e4SSQVHDRz8

(Client:)

local map = script.obj.Value
local mapController = require(game.ReplicatedStorage.MapController)
local platformController = require(mapController.PlatformController)
local platforms = map.platforms
local routeData = platformController.newData(3, false, true, {platforms.p1, platforms.p2, platforms.p3, platforms.p4})
local newPlatform = platformController.takeEffect(map.platform)
platformController.playData(routeData, newPlatform)

(Module:)

local module = {}

function module.newData(duration, reverse, loop, route)
    local parsed = {}
    parsed = {
        Reversed = false;
        DurationEach = 1;
        Loop = false;
        Route = {};
    }

    for i = 1, #route do
        local v = route[i]
        if v then
            parsed.Route[i] = {Orientation = v.Orientation; Position = v.Position}
            v.CanCollide = false
        end
    end

    if duration then
        parsed.DurationEach = duration
    end

    if reverse then
        parsed.Reversed = reverse
    end

    if loop then
        parsed.Loop = loop
    end
    return parsed
end

function module.takeEffect(oldObject)
    local new = oldObject:Clone()
    new.Anchored = false
    new.Parent = oldObject.Parent
    oldObject:Destroy()

    local bodyPosition = Instance.new("BodyPosition")
    bodyPosition.Name = "bp"
    bodyPosition.MaxForce = Vector3.new(4000, 500000000, 4000)
    bodyPosition.P = 10000
    bodyPosition.Position = new.Position
    bodyPosition.Parent = new

    local bodyGyro = Instance.new("BodyGyro")
    bodyGyro.Name = "bg"
    bodyGyro.MaxTorque = Vector3.new(3999999947964416, 399999991808, 400000001507328)
    bodyGyro.MaxTorque = Vector3.new(4000, 500000000, 4000)
    bodyGyro.P = 3000
    bodyGyro.D = 500
    bodyGyro.CFrame = CFrame.new()
    bodyGyro.Parent = new

    return new
end

function module.playData(data, object)
    if object and typeof(data) == "table" then
        local motionDuration, boolReversed, tableRoute = data.DurationEach, data.Reversed, data.Route
        local tweenings = {}

        for i, v in ipairs(tableRoute) do
            local tweenInfo = TweenInfo.new(motionDuration, Enum.EasingStyle.Quint, Enum.EasingDirection.InOut, 0, false, 0)
            tweenings[i] = {
                OrientationTween = game:GetService("TweenService"):Create(object, tweenInfo, {Orientation = v.Orientation;});
                PositionTween = game:GetService("TweenService"):Create(object.bp, tweenInfo, {Position = v.Position;});
            }
        end

        coroutine.resume(coroutine.create(function()
            while wait() do
                for _, v in ipairs(tweenings) do
                    v.PositionTween:Play()
                    v.OrientationTween:Play()
                    v.PositionTween.Completed:Wait()
                end
            end
        end))
    end
end

return module

Answer this question