So basically i am trying to do some moving platforms and i want the player locked to them while there is a tween so i found this script, it’s the first time i use Ray, but i’ve still understood it.
But there is a problem and i can’t find out how to fix it. I don’t really know how to explain it here is the video.
the script is this one
local tableee = {"1stblock", "2ndblock", "3rdblock", "4rdblock", "5thblock", "6thblock"}
local Players = game:GetService("Players")
local player = game.Players.LocalPlayer
local RunService = game:GetService('RunService')
local LastTrainCFrame
local Function
Function = RunService.Heartbeat:Connect(function()
--------------------------------------------------------------- CHECK PLATFORM BELOW
local RootPart = player.Character:WaitForChild("HumanoidRootPart")
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 table.find(tablee, Hit.Name) then -- Change "RaftTop" to whatever the moving part's name is
print("yez")
--------------------------------------------------------------- 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
end)
And then there is a tween for every platform
local tween1 = game:GetService("TweenService"):Create(blockone, TweenInfo.new(4,Enum.EasingStyle.Linear,Enum.EasingDirection.InOut, -1, true, 2), {CFrame = game.Workspace:WaitForChild("1stblockCFRAme").CFrame})
tween1:Play()
local tween2 = game:GetService("TweenService"):Create(blocktwo, TweenInfo.new(1,Enum.EasingStyle.Exponential,Enum.EasingDirection.InOut, -1, true, 2), {CFrame = game.Workspace:WaitForChild("2ndblockCFRame").CFrame})
tween2:Play()
local tween3 = game:GetService("TweenService"):Create(blockthree, TweenInfo.new(3,Enum.EasingStyle.Linear,Enum.EasingDirection.InOut, -1, true, 1), {CFrame = game.Workspace:WaitForChild("3rdblockCFRAmw").CFrame})
tween3:Play()
local tween4 = game:GetService("TweenService"):Create(blockfour, TweenInfo.new(5,Enum.EasingStyle.Sine,Enum.EasingDirection.InOut, -1, true, 1), {CFrame = game.Workspace:WaitForChild("4rdblockCFRAME").CFrame})
tween4:Play()
local tween5 = game:GetService("TweenService"):Create(blockfive, TweenInfo.new(2.5,Enum.EasingStyle.Bounce,Enum.EasingDirection.InOut, -1, true, .01), {CFrame = game.Workspace:WaitForChild("5thblockCFramE").CFrame})
tween5:Play()
local tween6 = game:GetService("TweenService"):Create(block6, TweenInfo.new(4,Enum.EasingStyle.Sine,Enum.EasingDirection.InOut, -1, true, .5), {CFrame = game.Workspace:WaitForChild("6thblockCFRA").CFrame})
tween6:Play()
The script are in starterPlayerScripts btw. Every answer is welcome and please, since i’m still beginner with Ray, i’d be grateful if you could explain me your answer/s :))