I’m trying to rewrite the animation code and use procedural animation, but I first need to figure out how to even cast the attachments on the ground. When the game starts everything is in it’s place, but I get an error saying that the instances rightLeg
and leftLeg
don’t exist. On top of that, the forums are kind of confusing and I want to avoid a migraine.
Error message: Workspace.Lil_devboy123.Animate:30: attempt to index nil with 'FilterDescendantsInstances' - Client - Animate:30
Code:
local players = game:GetService("Players")
local player = players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
if not char then
repeat wait() until char
char = player.Character
end
local rightLeg = char:FindFirstChild("Right Leg") or char:WaitForChild("Right Leg")
local leftLeg = char:FindFirstChild("Left Leg") or char:WaitForChild("Left Leg")
local RS = game:GetService("RunService")
local Workspace = game:GetService("Workspace")
if leftLeg and rightLeg then
local leftA = Instance.new("Attachment")
local rightA = Instance.new("Attachment")
leftA.Visible = true
rightA.Visible = true
leftA.Parent = leftLeg
rightA.Parent = rightLeg
RS.RenderStepped:Connect(function()
local rayOrigin = rightLeg.Position
local rayDirection = Vector3.new(0, -100, 0)
raycastParams.FilterDescendantsInstances = {leftLeg, rightLeg}
raycastParams.FilterType = Enum.RaycastFilterType.Exclude
local raycastResult = Workspace:Raycast(rayOrigin, rayDirection, raycastParams)
local raycastParams = RaycastParams.new()
rightA.Position = rightLeg.Position + raycastResult.Distance
end)
end