Attempt to index nil with 'Stop'

Hello :smiley:
i tried to make a simple script that when a player press button a lopped idle animation start and when player press it agein its stop

attempt to index nil with 'Stop'

local UserInputService = game:GetService("UserInputService")
local idle = script.idle
local idleAnim
local deb = false
local eqd = false


UserInputService.InputBegan:Connect(function(Input, istyping)
	if istyping then return end
	if Input.KeyCode == Enum.KeyCode.T and deb == false and eqd == false then
		deb = true
		eqd = true
		local idleAnim = Humanoid:LoadAnimation(idle)
		idleAnim:Play()
		wait(0.3)
		deb = false
	elseif Input.KeyCode == Enum.KeyCode.T and deb == false and eqd == true then
		deb = true
		eqd = false
		local Player = game.Players.LocalPlayer
		local Character = Player.Character
		local Humanoid = Character:WaitForChild("Humanoid")
		idleAnim:Stop()
		deb = false
	end

i tried to make the idle animation separed of the rest of the script but dont work, and this script that i show its just showing the parts that need to be fixed is not the entire script.

Its on R6.

6 Likes
local UserInputService = game:GetService("UserInputService")
local idle = script.idle
local idleAnim
local deb = false
local eqd = false


UserInputService.InputBegan:Connect(function(Input, istyping)
	if istyping then return end
	if Input.KeyCode == Enum.KeyCode.T and deb == false and eqd == false then
		deb = true
		eqd = true
		idleAnim = Humanoid:LoadAnimation(idle)
		idleAnim:Play()
		wait(0.3)
		deb = false
	elseif Input.KeyCode == Enum.KeyCode.T and deb == false and eqd == true then
		deb = true
		eqd = false
		local Player = game.Players.LocalPlayer
		local Character = Player.Character
		local Humanoid = Character:WaitForChild("Humanoid")
		idleAnim:Stop()
		deb = false
	end
3 Likes

sorry i forgot to say but the error is on idleAnim:Stop() in elseif

1 Like

hey what did you change, i dont really understand

1 Like

in the if statement when you put

local idleAnim = Humanoid:LoadAnimation(idle)

you set it as local which basically means that only in that if statement had the variable change and not the whole script, so you just remove the local

2 Likes

thanks
you did it now its working <3

2 Likes

Try This maybe the input function is executing too fast

1 Like

yes i was feeling that was a little laggy to that really help to thx :smiley:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.