Hello Developers,
So I am scripting a basketball. And when I go and pick it up it always brings up an error about the character and the animation doesn’t play. I’m not sure if I variabled the character right or not.
The Code:
local Tool = script.Parent.Parent
local Player = game.Players.LocalPlayer
local Character = Player.Character
local Humanoid = Character:WaitForChild("Humanoid")
local Animations = game.ReplicatedStorage:FindFirstChild("BallAnimations"):GetChildren()
local RDribble = Humanoid:LoadAnimation(Animations:FindFirstChild("RightDribble"))
local LDribble = Humanoid:LoadAnimation(Animations:FindFirstChild("LeftDribble"))
Tool.Equipped:Connect(function()
RDribble:Play()
end)
If the error is to do with the character, it’s possible the character didn’t load properly yet. I’d try making sure the character was added by replacing line 3 with:
local Character = Player.Character or Player.CharacterAdded:Wait()
This line will yield the script (wait) for the character to be added before it continues on, ensuring you can reference to properties and children of the character later in the script.
Feel free to send a screenshot of the error so we can determine if the error was in fact to do with the character not loading or if it’s to do with the actual animations.
is the animation script a local script? if it’s not, that might explain the error in line 3. game.Players.LocalPlayer only works within local scripts. also, i’m not sure if this is standard practice or not, but you should probably format game.Players as game:GetService("Players").
oh, holdon, i think you misinterpreted what i meant
what you wanna write is game:GetService("Players").LocalPlayer if you made the script into a localscript. i just meant that changing game.Players to game:GetService("Players") is typically better practice iirc