For some reason when I click this button it won’t play the animation and yes the animation priory is set to to Core.
local id = script.Parent.Name
local anim = Instance.new("Animation")
anim.Parent = script.Parent
anim.AnimationId = "rbxassetid://"..id
local track = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(anim)
local db = false
script.Parent.MouseButton1Click:Connect(function()
if db == false then
db = true
track:Play()
else
db = false
track:Stop()
end
end)
while true do
wait()
for i = 1, 840 do
local irox = script.Parent.ImageRectOffset.X
local iroy = script.Parent.ImageRectOffset.Y
script.Parent.ImageRectOffset = Vector2.new(irox +0.5, iroy +0.5)
wait()
end
wait()
script.Parent.ImageRectOffset = Vector2.new(0, 0)
end
The LocalPlayer’s character may be nil at the time of indexing it.
You should define it as a variable which would :Wait() on CharacterAdded if it is nil:
local player = game:GetService("Players").LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local track = character:WaitForChild("Humanoid"):LoadAnimation(anim)
That is a good catch, but he did post the hierarchy and he did not mention any errors. The local script is within the StarterGUI. Anything placed in the StarterGUI isn’t going to replicate until the Character is spawned.
The GUIs and consequently the scripts inside get deleted when the character respawns as this is all inside the StarterGUI as I stated before. That event will never trigger in this case.
Use a different animation priority. All character animations run at the Core priority and the Jump animation runs at the Idle priority. Your animation could be getting overwritten by default animations.
Then I don’t think it would be an issue because it would wait until the Character is spawned before running the script at all. I normally don’t have issues of the Player being nil.