This is my script for a crouch system. All of a sudden, it stopped working and keeps giving me this error "LoadAnimation requires the Animator object (Animator) to be a descendant of the game object"
. I don’t know what is wrong. Help
Server:
game.Players.PlayerAdded:connect(function(plr)
repeat wait() until plr.Character
local animator = Instance.new("Animator",plr.Character.Humanoid)
end)
Client:
local UserInputService = game:GetService("UserInputService")
local character = game.Players.LocalPlayer.Character
local humanoid = character:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator", 10)
local isCrawling = false
while character.Parent == nil do
character.AncestryChanged:wait()
end
repeat wait() until animator
local crawlAnim = animator:LoadAnimation(script.Crouch)
repeat wait() until character.Parent.Name == "Human"
humanoid.Running:Connect(function(speed)
if speed < 1 then
crawlAnim:Stop()
humanoid.WalkSpeed = 16
humanoid.JumpPower = 50
isCrawling = false
script.Parent.Parent.Parent.Parent.Human.Backpack.List.Visible = true
end
end)
UserInputService.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.Q then
if not isCrawling then
isCrawling = true
crawlAnim:Play()
crawlAnim:AdjustSpeed(0)
humanoid.WalkSpeed = 4
humanoid.JumpPower = 0
script.Parent.Parent.Parent.Parent.Human.Backpack.List.Visible = false
else
crawlAnim:Stop()
humanoid.WalkSpeed = 16
humanoid.JumpPower = 50
isCrawling = false
script.Parent.Parent.Parent.Parent.Human.Backpack.List.Visible = true
end
end
end)
script.Parent.MouseButton1Click:Connect(function()
if not isCrawling then
isCrawling = true
crawlAnim:Play()
humanoid.WalkSpeed = 4
humanoid.JumpPower = 0
script.Parent.Parent.Parent.Parent.Human.Backpack.List.Visible = false
else
crawlAnim:Stop()
humanoid.WalkSpeed = 16
humanoid.JumpPower = 50
isCrawling = false
script.Parent.Parent.Parent.Parent.Human.Backpack.List.Visible = true
end
end)