I keep getting errors as soon as I touch the ball

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.

I tried that but I think the problem was I kept putting the () then wait()

That didn’t solve the problem. Thanks for the suggestion doe

remove the :GetChildren() bit from that line, it’s not needed in this instance.

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").

Its in a serverscript do you want me to change it to a clientscript(“LocalScript”)

Was about to say the same, looks like it’s a server script so can’t use Players.LocalPlayer

ohhh then thats a my bad on my part

Is this related to it?
image

1 Like

Na thats another ball that ima delete later

1 Like

yeah, i suggest changing it to a localscript! animations typically are done in localscripts anyway

2 Likes

Um.

I changed it to a local script and still the same problem

You’re getting the Players Service, but not the LocalPlayer oof

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