How to make a player stay on a place when it moves

So I made a script here:

wait(1)
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()

local place = "None"

for i, v in pairs(script.Parent:GetChildren()) do
	if v:IsA("TextButton") then
		v.Activated:Connect(function()
			local boat = workspace.Boats:WaitForChild(v.Name)
			place = v.Name
		end)
	end
end

while true do
	if place == "Large" then
		local boat = workspace.Boats:WaitForChild(place)
		char.HumanoidRootPart.CFrame = boat.CFrame + Vector3.new(0, 10, 0)
	elseif place == "Small" then
		local boat = workspace.Boats:WaitForChild(place)
		char.HumanoidRootPart.CFrame = boat.CFrame + Vector3.new(0, 10, 0)
	elseif place == "Medium" then
		local boat = workspace.Boats:WaitForChild(place)
		char.HumanoidRootPart.CFrame = boat.CFrame + Vector3.new(0, 10, 0)
	end
	wait()
end

That would put your character on a certain boat if a button is pressed.
BUT, the character will stay stuck in the air in the while loop. Also, this only happens on the client.

So how would I make the player stay on the boat when it moves? Like:

  1. Player goes on small boat
  2. Small boat moves
  3. Player moves along with boat

Won’t

thing.Changed:Connect(function(change)
    if change == "Position" then
        --do code
    end
end)

work?

See here for more information:

1 Like

Thanks a lot! I literally just copy and pasted the code and changed it up a bit :slight_smile: