Animation refuses to stop

The title pretty much explains it all. My animation… Just wont stop. Yes, the remotes are working and all, theres even checks for it!

game.ReplicatedStorage.STORAGE.Remotes.DribbleBall.OnServerEvent:Connect(function(player)
	local char = player.Character
	local dribbling = char:WaitForChild("Dribbling")
	dribbling.Value = true	
		if dribbling.Value == true then
		motor6d.Part0  =  char.HumanoidRootPart
		animation = char.Humanoid:LoadAnimation(animations.Dribble)
		animation:Play()
		ball.Parent = char
	end
	
	game.ReplicatedStorage.STORAGE.Remotes.DropBall.OnServerEvent:Connect(function(player)
		dribbling.Value = false
		animation.Looped = false
		animation:Stop()
		end)
	end)
3 Likes

theres no variable of the animation
change it to this:

local animation = char.Humanoid:LoadAnimation(animations.Dribble)

not sure if thats not the problem though. lmk.

1 Like

I did that before, and it didn’t get the variable.

1 Like

Declare the variable outside because the other function doesn’t have the scope of the variable of the first function.

Example:

function foo()
    local variable = 10 --'variable' is only exclusive to function 'foo()'
end

function printer()
    print(variable) -- prints 'nil' because 'variable' is not a global variable
end

-- Edit: by removing the 'local' keyword, it just makes it a global variable, my bad

Here’s the code:

local animation
local dribbling

game.ReplicatedStorage.STORAGE.Remotes.DribbleBall.OnServerEvent:Connect(function(player)
	local char = player.Character
	dribbling = char:WaitForChild("Dribbling")
	dribbling.Value = true	
		if dribbling.Value == true then
		motor6d.Part0  =  char.HumanoidRootPart
		animation = char.Humanoid:LoadAnimation(animations.Dribble)
		animation:Play()
		ball.Parent = char
	end
	
	game.ReplicatedStorage.STORAGE.Remotes.DropBall.OnServerEvent:Connect(function(player)
		dribbling.Value = false
		animation.Looped = false
		animation:Stop()
		end)
	end)

lmk if that fixes it or not

2 Likes

You shouldn’t nest connections within other connections.

local animation --so both functions have access to the variable

game.ReplicatedStorage.STORAGE.Remotes.DribbleBall.OnServerEvent:Connect(function(player)
	local char = player.Character
	local dribbling = char:WaitForChild("Dribbling")
	if not dribbling then return end
	if dribbling.Value then return end --make sure the ball isnt being dribbled
	dribbling.Value = true	
	motor6d.Part0 = char.HumanoidRootPart
	ball.Parent = char
	animation = char.Humanoid:LoadAnimation(animations.Dribble)
	animation:Play()
end)

game.ReplicatedStorage.STORAGE.Remotes.DropBall.OnServerEvent:Connect(function(player)
    local char = player.Character
	local dribbling = char:WaitForChild("Dribbling")
	if not dribbling then return end
    if not dribbling.Value then return end --make sure the ball is being dribbled
	dribbling.Value = false
	animation.Looped = false
	animation:Stop()
end)
2 Likes

Apparently, it dosen’t work, sadly.

1 Like

For some reason, the event stopped listening.

1 Like

Dont nest events. Try this

local AllPlayingAnims = {}

local function PlayAnim(player)
	
	local char = player.Character
	local dribbling = char:WaitForChild("Dribbling")
	dribbling.Value = true	
	if dribbling.Value == true then
		motor6d.Part0  =  char.HumanoidRootPart
		animation = char.Humanoid:LoadAnimation(animations.Dribble)
		AllPlayingAnims[player] = animation
		animation:Play()
		ball.Parent = char
	end
end

local function StopAnim(player)
	
	if not AllPlayingAnims[player] then return end
	dribbling.Value = false
	AllPlayingAnims[player].Looped = false
	AllPlayingAnims[player]:Stop()
	AllPlayingAnims[player] = nil
end

game.ReplicatedStorage.STORAGE.Remotes.DribbleBall.OnServerEvent:Connect(PlayAnim)
game.ReplicatedStorage.STORAGE.Remotes.DropBall.OnServerEvent:Connect(StopAnim)
1 Like

Passed value is not a function.

1 Like

fixed try now 30charcharcharchar

1 Like

Now for some reason… It just stopped working.

1 Like

what stopped working? the animation not playing?

1 Like

No. When I press Z, it prints (“dropped”) but it’s still playing.

1 Like

add a print statement in StopAnim function and confirms if it receiving any event on pressing Z and add a print statement in the if statement of Stop anim to check if its returning on the event.

1 Like

It’s not printing anything.

1 Like

so you not firing the event correctly, the code i shared is correct.

2 Likes

Is it supposed to be like this?

local function StopAnim(player)
print("s")
	if not AllPlayingAnims[player] then return end
	player.Character:WaitForChild("Dribbling").Value = false
	AllPlayingAnims[player].Looped = false
	AllPlayingAnims[player]:Stop()
	AllPlayingAnims[player] = nil
	motor6d:Destroy()
end
1 Like

.Looped is a little broken right now, and doesn’t replicate. This means it finishes on the server, but can loop on the client, so when you call :Stop, the server doesn’t send that to the client because it thinks the animation is completely finished, but the client thinks it’s still being looped and thus it keeps playing. If you switch to the server view, does it work correctly?

1 Like

is it printing “s”?? if no, then you not firing the event correctly and if yes, then put a print statement in the if condition like

if not AllPlayingAnims[player] then print("No anim return") return end
1 Like

It’s not printing s.

1 Like