Hey, everyoneI’ve been making a script that detects obstacles and check if you can jump over it with raycasts.
Something like this:
(great drawing skills i know)
However the 2nd ray returns nil when it shouldn’t,
here’s the code:
local FrontPosition = RaycastFront(Blob.RootPart)
if FrontPosition ~= nil then
if (FrontPosition.Position - Blob.RootPart.Position).Magnitude <= (Position - Blob.RootPart.Position).Magnitude and (FrontPosition.Position - Blob.RootPart.Position).Magnitude <= 2 then
local BlacklistTable = {Blob}
local function RaycastDown(Cast, Blacklist)
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = Blacklist
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
local raycastResult = workspace:Raycast(Cast, Cast - Vector3.new(0,100,0) * 500, raycastParams)
if raycastResult then
return raycastResult
end
end
local DownPosition = RaycastDown(FrontPosition.Position + Vector3.new(0,10000,0), BlacklistTable).Position
--[[^^ ERROR HAPPENS IN THIS LINE ^^ ]]
if (DownPosition - Blob.RootPart.Position) <= 6 then
Blob.RootPart.Position = DownPosition + Vector3.new(0,1,0)
Animations.MoveTo(Blob, Position)
break
end
end
end
Error: ServerScriptService.Blob Animations:131: attempt to index nil with ‘Position’
Sorry about messy code.
Any help is appreciated!