Hello, i can’t fix this error ahhh “Workspace.Foxy_TPlay451.Hit:10: attempt to index nil with ‘LoadAnimation’”
Code:
local UIS = game:GetService("UserInputService")
local rp = game:GetService("ReplicatedStorage")
local hit = rp.RemoteEvents:WaitForChild("Hit")
local Players = game:GetService("Players")
local lp = game:GetService("Players").LocalPlayer
local Hum = lp:FindFirstChildOfClass("Humanoid")
local Hit1 = Hum:LoadAnimation(script.Hit1)
local Hit2 = Hum:LoadAnimation(script.Hit2)
local Hit3 = Hum:LoadAnimation(script.Hit3)
print("Запуск")
UIS.InputBegan:Connect(function(input, _gameprocess)
if not _gameprocess then
if input.UserInputType == Enum.UserInputType.MouseButton1 then
print("Нажата кнопка")
hit:FireServer()
Hit1:Play()
end
end
end)
21:20:03.527 Hit1 is not a valid member of LocalScript “Workspace.Foxy_TPlay451.Hit” - Client - Hit:10
21:20:03.527 Stack Begin - Studio
21:20:03.527 Script ‘Workspace.Foxy_TPlay451.Hit’, Line 10 - Studio - Hit:10
21:20:03.527 Stack End - Studio
I mean it must be local Hum = lp.Character:FindFirstChildOfClass("Humanoid"), not the animation
The animation’s location is correct, but the humanoid location isn’t. It errored because of incorrect humanoid
local Players = game:GetService("Players")
local lp = game:GetService("Players").LocalPlayer
local Hum = lp:FindFirstChildOfClass("Humanoid")
The humanoid can not be grabbed via the player, As @neweve2323 stated, theres no humanoid in a player, You must grab it via character. Like so:
local Players = game:GetService("Players")
local char = Players.LocalPlayer.Character or Players.LocalPlayer.CharacterAdded:Wait()
local Hum = char:WaitForChild("Humanoid")
Second off. Its best to load animations inside the function you want to do, Since sometimes, objects dont fully load the second a script is ran.
Instead of
local Hit1 = Hum:LoadAnimation(script.Hit1)
local Hit2 = Hum:LoadAnimation(script.Hit2)
local Hit3 = Hum:LoadAnimation(script.Hit3)
print("Запуск")
UIS.InputBegan:Connect(function(input, _gameprocess)
if not _gameprocess then
if input.UserInputType == Enum.UserInputType.MouseButton1 then
print("Нажата кнопка")
hit:FireServer()
Hit1:Play()
end
end
end)
Do
print("Запуск")
UIS.InputBegan:Connect(function(input, _gameprocess)
if not _gameprocess then
if input.UserInputType == Enum.UserInputType.MouseButton1 then
local Hit1 = Hum:LoadAnimation(script.Hit1)
local Hit2 = Hum:LoadAnimation(script.Hit2)
local Hit3 = Hum:LoadAnimation(script.Hit3)
print("Нажата кнопка")
hit:FireServer()
Hit1:Play()
end
end
end)