I have a Rocket Launcher which is supposed to play an animation when used, reloaded, and idled. But if you die from something, the script won’t detect the animation again. Even if it’s there.
Error:
Shoot is not a valid member of LocalScript “Players.octav20071.Backpack.Rocket Launcher.Client”
Script:
local Tool = script.Parent
local Remote = Tool:WaitForChild("MouseLoc")
local Player = game:GetService("Players").LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local Animator = Humanoid:WaitForChild("Animator")
local ShootAnim = Animator:LoadAnimation(script.Shoot) -- error
local IdleAnim = Animator:LoadAnimation(script.Idle)
local Mouse = Player:GetMouse()
local CanShoot = Tool.CanShoot
function Remote.OnClientInvoke()
return Mouse.Hit.p
end
Tool.Activated:Connect(function()
if CanShoot.Value then
ShootAnim:Play()
end
end)
Tool.Equipped:Connect(function()
IdleAnim:Play()
end)
Tool.Unequipped:Connect(function()
script.Parent.Server.Reload:Stop()
IdleAnim:Stop()
end)
What is wrong?
Animations are loaded into an Animator which is parented to the players Character.Humanoid object.
Because the Players Character object is rebuilt when it respawns and the old one is destroyed, you will need to load animaitons every time the character loads in.
Try using the Player.CharacterAdded event to fire animation loading: Player | Roblox Creator Documentation
Changed it to the following:
local Player = game:GetService("Players").LocalPlayer
local ShootAnim
local IdleAnim
Player.CharacterAdded:Connect(function(Character)
local Humanoid = Character:WaitForChild("Humanoid")
local Animator = Humanoid:WaitForChild("Animator")
ShootAnim = Animator:LoadAnimation(script.Shoot)
IdleAnim = Animator:LoadAnimation(script.Idle)
end)
local Mouse = Player:GetMouse()
local CanShoot = Tool.CanShoot
But now it’s erroring:
CanShoot is not a valid member of Tool “Players.octav20071.Backpack.Rocket Launcher”
Again, even if it’s there. What??
1 Like
this error has nothing to do with the animations.
It simple saying that Tool has no members (either properties or children) named CanShoot.
You not showing code about tools in this issue, and you should probably make a separate thread for that, since this is about loading animations.