Hello! I am having an issue with the animation. The script is made on the local side, but if the player spams or swaps animations, the animation on this list will stop on the local side, but on the server side it is still playing. I don’t understand what to do about this…
we cant do anything without any script
local TS = game:GetService("TweenService")
local module = require(game:GetService("ReplicatedStorage").AnimModul)
local OutLine = module.Choose()
local AnimationTable = {
{
Name = "Hug1",
ID = "17447337606",
Color = Color3.fromRGB(0, 110, 255)
},
{
Name = "Hug2",
ID = "17447348111",
Color = Color3.fromRGB(97, 255, 129)
},
{
Name = "SitR1",
ID = "17436986899",
Color = Color3.fromRGB(255, 0, 0)
},
{
Name = "SitR2",
ID = "17437713018",
Color = Color3.fromRGB(0, 13, 255)
},
{
Name = "SitR3",
ID = "17438194290",
Color = Color3.fromRGB(255, 0, 208)
},
{
Name = "SitR4",
ID = "17438447499",
Color = Color3.fromRGB(255, 0, 208)
}
}
local Frame = script.Parent.Frame
local Dummy = Frame.ViewportFrame.WorldModel.Rig
local Animator = Dummy.Humanoid.Animator
local Animation = Instance.new("Animation")
local RBLXAS = "rbxassetid://"
local ChoosenFrame = nil
local CPAnimation = nil
local PCPAnimation = nil
local db = false
local DummyAnimations = {}
local PlayerAnimations = {}
local Player = game:GetService("Players").LocalPlayer
local Idle = Instance.new("Animation")
Idle.AnimationId = RBLXAS.."10921301576"
local IdleAnimation = Animator:LoadAnimation(Idle)
IdleAnimation.Looped = true
IdleAnimation.Priority = Enum.AnimationPriority.Core
IdleAnimation:Play(0,1,1)
local function StopAnims(Table)
for Index, Anim in Table do
Anim:Stop(0)
table.remove(Table, Index)
end
end
local function OnClick(Button, AnimID)
if db then return end
db = true
if ChoosenFrame == Button then
if PCPAnimation then
StopAnims(PlayerAnimations)
PCPAnimation = nil
end
OutLine.Parent = nil
ChoosenFrame = nil
else
local Character = Player.Character
StopAnims(PlayerAnimations)
Animation.AnimationId = RBLXAS..AnimID
PCPAnimation = Character.Humanoid.Animator:LoadAnimation(Animation)
PCPAnimation.Priority = Enum.AnimationPriority.Action
PCPAnimation.Looped = true
PCPAnimation:Play(0.1,16,1)
table.insert(PlayerAnimations, PCPAnimation)
OutLine.Parent = Button
ChoosenFrame = Button
end
task.wait(0.25)
db = false
end
local function OnEnter(Button, AnimID)
if CPAnimation then StopAnims(DummyAnimations) end
Animation.AnimationId = RBLXAS..AnimID
CPAnimation = Animator:LoadAnimation(Animation)
CPAnimation.Looped = true
CPAnimation:Play(0,16,1)
table.insert(DummyAnimations, CPAnimation)
end
local function OnLeave(Button)
if CPAnimation then
StopAnims(DummyAnimations)
CPAnimation = nil
end
end
for Index, Table in pairs(AnimationTable) do
local Button = module.New(Index, Table.Name, Table.Color)
Button.MouseButton1Click:Connect(function()
if db then return end
OnClick(Button, Table.ID)
end)
Button.MouseEnter:Connect(function()
OnEnter(Button, Table.ID)
end)
Button.MouseLeave:Connect(function()
OnLeave(Button)
end)
end