Hello
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.
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
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