Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Animation not running cause Character index returns a nil value?

I'm wondering what is really the cause of my animation system not loading?

local player = game.Players.LocalPlayer
mouse = player:GetMouse()
enabled = true
local StPlr = game.StarterPlayer
local Rs = game.ReplicatedStorage

local Double = Rs.CurrentAnims:WaitForChild("Double")
local Back = Rs.CurrentAnims:WaitForChild("Back")
local Idle = Rs.CurrentAnims:WaitForChild("Idle")
local Down = Rs.CurrentAnims:WaitForChild("Down")
local Up = Rs.CurrentAnims:WaitForChild("Up")
local CharTr = player.Character

-- running idle	
while true do
	repeat
	local PlayIdle = CharTr.Humanoid:LoadAnimation(Idle)
	PlayIdle:Play()
	wait(2.5) 
	until
mouse.Button1Down:Connect(function()
	if enabled then
		enabled = false
		
		local PlayDoublePunch = CharTr.Humanoid:LoadAnimation(Double)
		PlayDoublePunch:Play()

		wait(1.5)

		enabled = true
	end
end)

mouse.KeyDown:Connect(function(k)
	if k == 'c' then
		print("C is pressed")
		if enabled then
			enabled = false
			local PlayBackPunch = CharTr.Humanoid:LoadAnimation(Back)
			PlayBackPunch:Play()
		
			wait(1.5)
			enabled = true
		end
	end
	if k == 'q' then
		print("Q is pressed")
		if enabled then
			enabled = false
			local PlayUp = CharTr.Humanoid:LoadAnimation(Up)
			PlayUp:Play()
		
			wait(1.5)
			enabled = true
		end
	end
	if k == 'z' then
		print("Z is pressed")
		if enabled then
			enabled = false
			local PlayDown = CharTr.Humanoid:LoadAnimation(Down)
			PlayDown:Play()
		
			wait(1.5)
			enabled = true
		end
	end
end)

end

Output was "attempt to index global CharTr(a nil value)"

1 answer

✓ Accepted answer

Hello, Stormtech6!

You just need to wait for the character to be created

local player = game.Players.LocalPlayer
mouse = player:GetMouse()
enabled = true
local StPlr = game.StarterPlayer
local Rs = game.ReplicatedStorage

local Double = Rs.CurrentAnims:WaitForChild("Double")
local Back = Rs.CurrentAnims:WaitForChild("Back")
local Idle = Rs.CurrentAnims:WaitForChild("Idle")
local Down = Rs.CurrentAnims:WaitForChild("Down")
local Up = Rs.CurrentAnims:WaitForChild("Up")
repeat wait() until player.Character --Waits for the character to be created
local CharTr = player.Character

-- running idle 
while true do
    repeat
    local PlayIdle = CharTr.Humanoid:LoadAnimation(Idle)
    PlayIdle:Play()
    wait(2.5) 
    until
mouse.Button1Down:Connect(function()
    if enabled then
        enabled = false

        local PlayDoublePunch = CharTr.Humanoid:LoadAnimation(Double)
        PlayDoublePunch:Play()

        wait(1.5)

        enabled = true
    end
end)

mouse.KeyDown:Connect(function(k)
    if k == 'c' then
        print("C is pressed")
        if enabled then
            enabled = false
            local PlayBackPunch = CharTr.Humanoid:LoadAnimation(Back)
            PlayBackPunch:Play()

            wait(1.5)
            enabled = true
        end
    end
    if k == 'q' then
        print("Q is pressed")
        if enabled then
            enabled = false
            local PlayUp = CharTr.Humanoid:LoadAnimation(Up)
            PlayUp:Play()

            wait(1.5)
            enabled = true
        end
    end
    if k == 'z' then
        print("Z is pressed")
        if enabled then
            enabled = false
            local PlayDown = CharTr.Humanoid:LoadAnimation(Down)
            PlayDown:Play()

            wait(1.5)
            enabled = true
        end
    end
end)

end

Good Luck with your games

This discussion is preserved as it was. New answers, comments, and votes are closed.