The raycast hits all other parts normally but as soon as it touches a moving part it says its nil. The part is being moved using tweens so that might have to do with it. I also haven’t put in anything to ignore
Tweens wouldn’t affect it. Can you share the code you’re using to raycast and the code you’re using to move the object?
This is the code Im using to raycast:
local Players = game:GetService("Players")
local player = game.Players.LocalPlayer
local RunService = game:GetService('RunService')
local LastTrainCFrame
local Function
local Function2
for i, v in pairs(game.Workspace:GetChildren()) do
end
Function = RunService.Heartbeat:Connect(function()
--------------------------------------------------------------- CHECK PLATFORM BELOW
local char = player.Character
local RootPart = char.LowerTorso
local Ignore = player.Character
local ray = Ray.new(RootPart.CFrame.p,Vector3.new(0,-5,0))
local Hit, Position, Normal, Material = game.Workspace:FindPartOnRay(ray)
local distance = (RootPart.CFrame.p - Position).Magnitude
local p = Instance.new("Part")
p.Anchored = true
p.CanCollide = false
p.Size = Vector3.new(0.1, 0.1, distance)
p.CFrame = CFrame.lookAt(RootPart.CFrame.p, Position)*CFrame.new(0, 0, -distance/2)
p.Parent = game.Workspace
print(game.Workspace:FindPartOnRay(ray,player.Character))
-- for i, v in pairs(game.Workspace:GetChildren()) do
if Hit and Hit.Name == "0,0,50:1" then -- Change "RaftTop" to whatever the moving part's name is
--------------------------------------------------------------- MOVE PLAYER TO NEW POSITON FROM OLD POSITION
print("in2")
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(RootPart.CFrame)
else
LastTrainCFrame = nil -- Clear the value when the player gets off.
end
-- end
Function2 = player.Character.Humanoid.Died:Connect(function()
Function:Disconnect() -- Stop memory leaks
Function2:Disconnect() -- Stop memory leaks
end)
end)
and this is the code to move the parts:
local TweenService = game:GetService("TweenService")
local RunService = game:GetService("RunService")
local partstable = {}
local positiontable = {}
local physics = game:GetService("PhysicsService")
local spawns = game.Workspace.Spawns
for i, v in pairs(spawns:GetChildren()) do
local name = "Level"..v.Name
local folder = game.Workspace:WaitForChild(name)
for x, z in pairs(folder.MovingParts:GetChildren()) do
local index = tostring(i)..tostring(x)
partstable[index] = z
end
end
for i, v in pairs(partstable) do
if v:IsA("BasePart") then
physics:SetPartCollisionGroup(v, "ClientParts")
local name = v.Name
local nametable = string.split(name, ":")
local coordinates = nametable[1]
local tweentime = tonumber(nametable[2])
local specifictable = string.split(coordinates, ",")
local x = specifictable[1]
local y = specifictable[2]
local z = specifictable[3]
local tweenInfo = TweenInfo.new(
tweentime,
Enum.EasingStyle.Linear,
Enum.EasingDirection.In,
-1,
true,
0
)
local tween = TweenService:Create(v, tweenInfo, {Position = v.Position + Vector3.new(x,y,z)})
tween:Play()
end
end
for i, v in pairs(partstable) do
if v:IsA("BasePart") then
positiontable[i] = v.Position
end
end
RunService.Stepped:Connect(function(_, deltatime)
for i, v in pairs(partstable) do
if v:IsA("BasePart") then
local currentposition = v.Position
local deltapos = currentposition-positiontable[i]
local velocity = deltapos/deltatime
v.AssemblyLinearVelocity = velocity
positiontable[i] = currentposition
end
end
end)