#Animation still plays even after unquippeded

1 messages · Page 1 of 1 (latest)

slender badger
#

local players = game.Players.LocalPlayer
local anim1 = script.Parent.Animation
local anim2 = script.Parent.FireAnimation

local anim = script.Parent.Rest

local camera = game.Workspace.CurrentCamera

local track
local track2
local trackA

local UIS = game:GetService("UserInputService")

local CanFire = false

script.Parent.Equipped:Connect(function()

track = players.Character.Humanoid:LoadAnimation(anim1)
track:play()
end)

script.Parent.Unequipped:Connect(function()
    trackA = players.Character.Humanoid:LoadAnimation(anim)
    track:stop()
    trackA:stop()
end)

local debouce = false

script.Parent.Activated:Connect(function()
    if debouce == false then
        debouce = true
    track2 = players.Character.Humanoid:LoadAnimation(anim2)
    track2:play()
        camera.CFrame = camera.CFrame * CFrame.Angles(.005,math.rad(.5),0)
        wait(.01)
        camera.CFrame = camera.CFrame * CFrame.Angles(.0015,math.rad(.8),0)
        wait(.01)
        camera.CFrame = camera.CFrame * CFrame.Angles(.002,math.rad(.5),0)
        wait(.01)
        camera.CFrame = camera.CFrame * CFrame.Angles(-.0015,math.rad(0),0)
        wait(.01)
        camera.CFrame = camera.CFrame * CFrame.Angles(-.005,math.rad(0),0)
        wait(.01)
        camera.CFrame = camera.CFrame * CFrame.Angles(-.002,math.rad(0),0)
        
    debouce = false
end
end)

local Temp = false

UIS.InputBegan:Connect(function(key)
    if players.Character:FindFirstChild("M911") then
        if key.KeyCode == Enum.KeyCode.E then

    
            if Temp == false then
                Temp = true
                print("K")
                trackA = players.Character.Humanoid:LoadAnimation(anim)
                trackA:play()
            elseif Temp == true then
                Temp = false
                trackA:stop()
            end
        end
    end
end)
daring moat
#

any errors?

slender badger
#

No theres no errors

daring moat
#

wait a minute what's the "script.Parent"

slender badger
daring moat
#

ok so where is this tool?

slender badger
#

Its in the character

daring moat
slender badger
#

Yeah

daring moat
#

ok so what you're actually changing isn't the tool in workspace you're changing the tool that gets cloned to workspace. and the solution would be get the tool from workspace instead inside the character

#

so something like this:

local player = game.Players.LocalPlayer
local characterModel = workspace:WaitForChild(player.Name)
local tool = characterModel:WaitForChild("M911")
slender badger
daring moat
slender badger
# daring moat any errors?

Theres no errors but now when I click e for any other tool, it also plays the animation. instead of just playing it for this specific tool

runic oakBOT
#

studio** You are now Level 8! **studio

slender badger
#

local players = game.Players.LocalPlayer
local anim1 = script.Parent.Animation
local anim2 = script.Parent.FireAnimation

local anim = script.Parent.Rest

local camera = game.Workspace.CurrentCamera

local characterModel = workspace:WaitForChild(players.Name)
local tool = characterModel:WaitForChild("M911")

local track
local track2
local trackA

local UIS = game:GetService("UserInputService")

local CanFire = false

script.Parent.Equipped:Connect(function()

track = players.Character.Humanoid:LoadAnimation(anim1)
track:play()
end)

script.Parent.Unequipped:Connect(function()
    trackA = players.Character.Humanoid:LoadAnimation(anim)
    track:stop()
    trackA:stop()
end)

local debouce = false

script.Parent.Activated:Connect(function()
    if debouce == false then
        debouce = true
    track2 = players.Character.Humanoid:LoadAnimation(anim2)
    track2:play()
        camera.CFrame = camera.CFrame * CFrame.Angles(.005,math.rad(.5),0)
        wait(.01)
        camera.CFrame = camera.CFrame * CFrame.Angles(.0015,math.rad(.8),0)
        wait(.01)
        camera.CFrame = camera.CFrame * CFrame.Angles(.002,math.rad(.5),0)
        wait(.01)
        camera.CFrame = camera.CFrame * CFrame.Angles(-.0015,math.rad(0),0)
        wait(.01)
        camera.CFrame = camera.CFrame * CFrame.Angles(-.005,math.rad(0),0)
        wait(.01)
        camera.CFrame = camera.CFrame * CFrame.Angles(-.002,math.rad(0),0)
        
    debouce = false
end
end)

local Temp = false

UIS.InputBegan:Connect(function(key)
    if tool then
        if key.KeyCode == Enum.KeyCode.E then

            if Temp == false then
                Temp = true
                print("K")
                trackA = players.Character.Humanoid:LoadAnimation(anim)
                trackA:play()
            elseif Temp == true then
                Temp = false
                trackA:stop()
            end
        end
    end
end)
daring moat
#

bro you didn't use the tool variable

#

you said script.Parent.Equipped instead of tool.Equipped

slender badger
#

Oh

daring moat
#

so everytime you say script.Parent replace it with tool variable instead

#

@slender badger so did it work?

slender badger
#

theres an error

#

"Infinite yield possible on 'Workspace.Nullendex:WaitForChild("M911")' "

daring moat
#

oh ok so where is the tool cloned in the character when you run the game send a screenshot of the explorer

slender badger
daring moat
#

oh ok so the tool isn't always inside the character so you should replace WaitForChild on the tool variable to FindFirstChild instead and then say if tool then

local tool = characterModel:FindFirstChild("M911")
if tool then
-- rest of ur code that uses tool variable
end
slender badger
#

Alright I'll try it

slender badger
daring moat
#

@slender badger try saying :Play() and :Stop() instead of :play() and :stop()

slender badger
#

"Infinite yield possible on 'Workspace.Nullendex:WaitForChild("M911")'"

daring moat
#

bro

#

I told you to use FindFirstChild instead

slender badger
#

I did findfirstchild, and the animation wouldn't even play? so I did waitforchild and findfirstchild

daring moat
#

well WaitForChild will just throw an infinite yield error because the tool isn't always in the character

grizzled lagoon
#

what is the problem here?

slender badger
grizzled lagoon
daring moat
#

pretty sure

grizzled lagoon
daring moat
grizzled lagoon
#

I dont think you could stop an animation from diff track.

#

@slender badger , just make it global

#

because ur creating a new track of an animation which hasnt been played and you stopped it

#

which doesnt make anysense, however if u make the animation track becomes global. It'll recognize the animation track and stop it

daring moat
grizzled lagoon
#

it just plays

#

oh my fudge

#

My bad

#

he indeed made it global

#

I dont see anything wrong beside stop and play

#

my bad chat

daring moat
#

yeah I just tested it and it does work

#

so what the hell is causing this problem

grizzled lagoon
#

:stop and :play

daring moat
#

idrk if he did

daring moat
slender badger
#

Yes

daring moat
#

and still nothing?

#

@slender badger ok so I was wrong about the tool thing just leave it as script.Parent my bad

slender badger
#

alr

daring moat
#

@slender badger so does it work now?

slender badger
floral spruce
#

youre trying to stop a completely different thing

#

make a global variable that loads the animation and manipulate only it

#
local track = players.Character.Humanoid:LoadAnimation(anim1)

function onEquip()
  track:Play()
end

function unEquip()
  track:Stop()
end
daring moat
floral spruce
#

Every

#

Single

#

Time

#

So they keep stacking

#

Thats why he needs yo do hlobal variabkes for his animayions loading them only once.