Having issues moving player with part

Hello! I’ve been having an issue with moving the player with a part. I used the script from this post, but instead it does this:


Just to clarify, it has nothing to do with the character’s rig type because earlier today I used it on an R6 game and it worked fine.

You can change the script to move the player’s character model to the position of the moving platform rather than updating the player’s CFrame relative to the moving platform. This should ensure that the player’s character model moves with the platform.

My Approach

local Players = game:GetService("Players")
local player = game.Players.LocalPlayer
local RunService = game:GetService('RunService')

local LastTrainCFrame

local Function
local Function2

Function = RunService.Heartbeat:Connect(function()
    --------------------------------------------------------------- CHECK PLATFORM BELOW

    local RootPart = player.Character.LowerTorso

    local Ignore = player.Character

    local ray = Ray.new(RootPart.CFrame.p, Vector3.new(0, -50, 0))

    local Hit, Position, Normal, Material = workspace:FindPartOnRay(ray, Ignore)

    if Hit and Hit.Name == "RaftTop" then -- Change "RaftTop" to whatever the moving part's name is
        --------------------------------------------------------------- MOVE PLAYER TO NEW POSITON FROM OLD POSITION

        local Train = Hit
        if LastTrainCFrame == nil then -- If no LastTrainCFrame exists, make one!
            LastTrainCFrame = Train.CFrame -- This is updated later.
        end
        local TrainCF = Train.CFrame

        local Rel = TrainCF * LastTrainCFrame:inverse()

        LastTrainCFrame = Train.CFrame -- Updated here.

        local newRootPartPosition = Rel * RootPart.Position -- Calculate the new position of the player's character model based on the platform's movement
        player.Character:SetPrimaryPartCFrame(CFrame.new(newRootPartPosition, newRootPartPosition + Vector3.new(0, 0.5, 0))) -- Set the new position of the player's character model

    else
        LastTrainCFrame = nil -- Clear the value when the player gets off.
    end

    Function2 = player.Character.Humanoid.Died:Connect(function()
        Function:Disconnect() -- Stop memory leaks
        Function2:Disconnect() -- Stop memory leaks
    end)

end)

This calculates the new position of the players model based on the movement of the platform using the SetPrimaryPartCFrame method.

Now it doesn’t move the player at all. No errors in output.

The user could possibly be anchored, we can try this approach with RootPart set as the PrimaryPart and a check.

Approach 2

local Players = game:GetService("Players")
local player = game.Players.LocalPlayer
local RunService = game:GetService('RunService')

local LastTrainCFrame

local Function
local Function2

Function = RunService.Heartbeat:Connect(function()
    --------------------------------------------------------------- CHECK PLATFORM BELOW

    local RootPart = player.Character.PrimaryPart

    local Ignore = player.Character

    local ray = Ray.new(RootPart.CFrame.p, Vector3.new(0, -50, 0))

    local Hit, Position, Normal, Material = workspace:FindPartOnRay(ray, Ignore)

    if Hit and Hit.Name == "RaftTop" then -- Change "RaftTop" to whatever the moving part's name is
        --------------------------------------------------------------- MOVE PLAYER TO NEW POSITON FROM OLD POSITION

        local Train = Hit
        if LastTrainCFrame == nil then -- If no LastTrainCFrame exists, make one!
            LastTrainCFrame = Train.CFrame -- This is updated later.
        end
        local TrainCF = Train.CFrame

        local Rel = TrainCF * LastTrainCFrame:inverse()

        LastTrainCFrame = Train.CFrame -- Updated here.

        local newRootPartPosition = Rel * RootPart.Position -- Calculate the new position of the player's character model based on the platform's movement

        -- Unanchor the character so that it can move freely
        player.Character:SetAttribute("IsAnchored", false)
        player.Character:SetPrimaryPartCFrame(CFrame.new(newRootPartPosition, newRootPartPosition + Vector3.new(0, 0.5, 0)))
        player.Character:SetAttribute("IsAnchored", true)

    else
        LastTrainCFrame = nil -- Clear the value when the player gets off.
    end

    Function2 = player.Character.Humanoid.Died:Connect(function()
        Function:Disconnect() -- Stop memory leaks
        Function2:Disconnect() -- Stop memory leaks
    end)
end)

I can confirm that the user’s primary part is not anchored, because I can move using the WASD keys. What I meant by “not moving” is that the script is not moving the player with the part or doing anything at all.

Hey there!

I’ve added some debug statements to see where everything ends, and what outputs. Would you mind giving this a try and a screenshot/gif of the output?

local Players = game:GetService("Players")
local player = game.Players.LocalPlayer
local RunService = game:GetService('RunService')

local LastTrainCFrame

local Function
local Function2

Function = RunService.Heartbeat:Connect(function()
    print("Checking platform...")
    --------------------------------------------------------------- CHECK PLATFORM BELOW

    local RootPart = player.Character.PrimaryPart

    local Ignore = player.Character

    local ray = Ray.new(RootPart.CFrame.p, Vector3.new(0, -50, 0))

    local Hit, Position, Normal, Material = workspace:FindPartOnRay(ray, Ignore)

    if Hit and Hit.Name == "RaftTop" then -- Change "RaftTop" to whatever the moving part's name is
        print("Player is on the platform!")

        --------------------------------------------------------------- MOVE PLAYER TO NEW POSITION FROM OLD POSITION

        local Train = Hit
        if LastTrainCFrame == nil then -- If no LastTrainCFrame exists, make one!
            LastTrainCFrame = Train.CFrame -- This is updated later.
        end
        local TrainCF = Train.CFrame

        local Rel = TrainCF * LastTrainCFrame:inverse()

        LastTrainCFrame = Train.CFrame -- Updated here.

        local newRootPartPosition = Rel * RootPart.Position -- Calculate the new position of the player's character model based on the platform's movement

        -- Unanchor the character so that it can move freely
        player.Character:SetAttribute("IsAnchored", false)
        player.Character:SetPrimaryPartCFrame(CFrame.new(newRootPartPosition, newRootPartPosition + Vector3.new(0, 0.5, 0)))
        player.Character:SetAttribute("IsAnchored", true)
        
        print("Moved player to new position:", newRootPartPosition)

    else
        print("Player is not on the platform!")
        LastTrainCFrame = nil -- Clear the value when the player gets off.
    end

    Function2 = player.Character.Humanoid.Died:Connect(function()
        Function:Disconnect() -- Stop memory leaks
        Function2:Disconnect() -- Stop memory leaks
    end)
end)