Made a looped animation, when i try to :Stop() it, nothing happens. Not much else to say other than the script is a server script.
Can you show the code in the script?
I would assume based on the limited information that the animation is being…
Not stopped correctly
Or is playing multiple times so stopping it once doesn’t stop all iterations
you can ignore all that profile service stuff, its not a finished script.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Event = ReplicatedStorage.Animation
local Players = game:GetService("Players")
local ServerScriptService = game:GetService("ServerScriptService")
local PlayerData = require(ServerScriptService.PlayerData.Manager)
local Defualt = script.DefualtSwing
local TPose = script.TPoseSwing
Event.OnServerEvent:Connect(function(player, new, humanoid)
local profile = PlayerData.Profiles[player]
if not profile then return end
local Hooked = player:WaitForChild("NumberOfHooks"):WaitForChild("Amount")
local DefualtTrack = humanoid:LoadAnimation(Defualt)
local TPoseTrack = humanoid:LoadAnimation(TPose)
if new == Enum.HumanoidStateType.Freefall then
if Hooked.Value == 1 then
DefualtTrack:Play()
end
elseif new == Enum.HumanoidStateType.Running then
DefualtTrack:Stop()
end
end)
Ok so the problem is being states:
To fix this issue here is a simple solution:
local Defualt = script.DefualtSwing
local TPose = script.TPoseSwing
Event.OnServerEvent:Connect(function(player, new, humanoid)
local profile = PlayerData.Profiles[player]
if not profile then return end
local Hooked = player:WaitForChild("NumberOfHooks"):WaitForChild("Amount")
local DefualtTrack = humanoid.Animator:LoadAnimation(Defualt)
local TPoseTrack = humanoid.Animator:LoadAnimation(TPose)
if new == Enum.HumanoidStateType.Freefall then
if Hooked.Value == 1 then
DefualtTrack:Play()
end
elseif new == Enum.HumanoidStateType.Running then
for i, animation in pairs(humanoid.Animator:GetPlayingAnimationTracks()) do
if tostring(animation.Name) == tostring(defualt.Name) then
animation:Stop()
end
end
end)
What this does is:
“for i, animation in pairs(humanoid.Animator:GetPlayingAnimationTracks()) do
if tostring(animation.Name) == tostring(defualt.Name) then
animation:Stop()
end”
It stops all the repeating animations created that are playing, though this is not the optimal solution to let animations being recreated constantly as that may cause lag here would be an improvement:
local Defualt = script.DefualtSwing
local TPose = script.TPoseSwing
Event.OnServerEvent:Connect(function(player, new, humanoid)
local profile = PlayerData.Profiles[player]
if not profile then return end
local Hooked = player:WaitForChild("NumberOfHooks"):WaitForChild("Amount")
local DefualtTrack = humanoid.Animator:LoadAnimation(Defualt)
local TPoseTrack = humanoid.Animator:LoadAnimation(TPose)
if new == Enum.HumanoidStateType.Freefall then
if Hooked.Value == 1 then
--Improvement Start:
local holderVal = 0
for i, animation in pairs(humanoid.Animator:GetPlayingAnimationTracks()) do
if tostring(animation.Name) == tostring(defualt.Name) then
holderVal = 1
end
end
if holderVal == 0 then
DefualtTrack:Play()
end
--Impovement End
end
elseif new == Enum.HumanoidStateType.Running then
for i, animation in pairs(humanoid.Animator:GetPlayingAnimationTracks()) do
if tostring(animation.Name) == tostring(defualt.Name) then
animation:Stop()
end
end
end)
Now what this imrpovement does is that it checks if the animation is playing or not for the player, if it is, it will not play it again, therefore solving the repeating issue too.
Some of the identation may be a little weird, my tab is not working well. (Please tell me if this fixed the problem).
This worked! Thank you!
Character limit
No problem! Happy to help you out!
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.