Player not attaching to tweening part

  1. What do you want to achieve? Keep it simple and clear!
    Player be able to walk on tweening part

  2. What is the issue? Include screenshots / videos if possible!
    script won’t work

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    changing the script but still no solution

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.HumanoidRootPart

	--Replace Ignore with this.
	local Whitelist = {game.Workspace.BasePart} -- Table of Every "RaftTop"  (You could just make a model or folder for it.)

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

	local Hit, Position, Normal, Material = workspace:FindPartOnRayWithWhitelist(ray,Whitelist)

	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.

		RootPart.CFrame = Rel * RootPart.CFrame -- Set the player's CFrame
		--print("set")

	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)

first check if the raycast even does something and if the currently commented print(“Set”) will run if you uncomment it

Do you get any errors? Did you name the part “RaftTop” (as is in your script)? Did you put the script in the “StarterCharacter” (or was it “StarterPlayer”)?

Anyways, ensure you’ve used the script properly, otherwise it won’t even do what you’re intending for it to do.

1 Like