My code is supposed to make an animation play for an idle animation. Its a rocket launcher, but the problem with it is that… It for some reason isn’t finding Humanoid, even though it has many times before?
I’ve tried doing :FindFirstChild and :WaitForChild, or character.Humanoid, but still nothing.
The animation priority is set to Idle, the animation is inside the localscript, which is inside the tool.
I will try to show what everything does, heres my code:
local tool = script.Parent -- gets the tool
local player = game.Players.LocalPlayer -- gets the player
local character = player.Character -- gets the character from the player
--idle
local idle = script:WaitForChild("Idle") -- idle is inside the script
local IdleAnim = character.Humanoid:LoadAnimation(idle) -- loads the animation, reference to the things i've already tried
tool.Equipped:Connect(function() -- if its equipped, play the animation
IdleAnim:Play()
end)
tool.Unequipped:Connect(function() -- if unequipped, stop the animation.
IdleAnim:Stop()
end)
Sorry for the very late reply, but perhaps the problem is that the script is loading too fast, and the character has not yet been added in yet, so you can do
local character = player.Character or player.CharacterAdded:Wait()
local tool = script.Parent -- gets the tool
local player = game.Players.LocalPlayer -- gets the player
repeat wait() until player.Character
local character = player.Character -- gets the character from the player
--idle
local idle = script:WaitForChild("Idle") -- idle is inside the script
local IdleAnim = character.Humanoid:LoadAnimation(idle) -- loads the animation, reference to the things i've already tried
tool.Equipped:Connect(function() -- if its equipped, play the animation
IdleAnim:Play()
end)
tool.Unequipped:Connect(function() -- if unequipped, stop the animation.
IdleAnim:Stop()
end)
local players = game:GetService("Players")
local player = players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local tool = script.Parent
local animation = script:WaitForChild("Idle")
local track = humanoid:LoadAnimation(animation)
tool.Equipped:Connect(function()
track:Play()
end)
tool.Unequipped:Connect(function()
track:Stop()
end)
Yep again, still character is nil… Can module scripts be used as a local script technically? Or are they just serverscripts. Either way, still not sure why character is nil. That might be my problem
ModuleScripts follow the context in which they were required in, they are treated as local if required by a local script script & treated as server if required by a server script.
Alright: Update, tried it and it gave me this error:
Equipped is not a valid member of Folder “Workspace.squaredsnow.RocketLauncher.Modules”
I just copy and pasted the script into a local script because theres nothing that would change. And the localscript is in the same place the serverscript was…
I changed the function name to Equip instead of Equipped, still the same error, i made a variable for the tool, and checked if it was equipped, but same error, heres where the error is:
local tool = script.Parent
local animation = script:WaitForChild("Idle")
local track = humanoid:LoadAnimation(animation)
tool.Equipped:Connect(function() -- error Equipped is not a valid member of Folder "Workspace.squaredsnow.RocketLauncher.Modules"
print("Track played")
track:Play()
end)