I’m working on a system that allows players to trigger an animation using /e command
for example (/e kneel = triggers an kneeling animation)
the script uses a Bool Value to track whether an animation is playing or not.
normally if a command was fired (/e kneel, /e sit etc) the bool value will be set to true and the animation would start playing, if the command is fired again while the value is true the value would turn false and the animation would stop.
my issue is whenever there are more players in the server the script tends to glitch out. while firing the command, the value would turn true than deactivates itself (turns false and stop the animation entirely) this glitch even if the value is true or false.
code below
local Player = game.Players.LocalPlayer
local Character = Player.Character
local pose1 = script.PlaceInChar:FindFirstChild("AnimPose1")
pose1.Parent = Character
local Pose1Finder = Player.Character.Humanoid.Animator:LoadAnimation(pose1)
toggle1 = script.Pose1.Active
game:GetService("Players").LocalPlayer.Chatted:connect(function(msg)
if msg == "/e praying" then
if toggle1.Value == false then
Pose1Finder:Stop(0.2)
toggle1.Value = true
pose1.AnimationId = script.Pose1.praying.AnimationId
anim1 = Character.Humanoid:LoadAnimation(pose1)
wait(0.2)
anim1:Play(0.7)
print("animation activated")
elseif toggle1.Value == true then
toggle1.Value = false
anim1:Stop(0.5)
print("animation deactivated")
end
end
if msg == "/e pushup" then
if toggle1.Value == false then
Pose1Finder:Stop(0.2)
toggle1.Value = true
pose1.AnimationId = script.Pose1.pushup.AnimationId
anim1 = Character.Humanoid:LoadAnimation(pose1)
wait(0.2)
anim1:Play(0.7)
print("animation activated")
elseif toggle1.Value == true then
toggle1.Value = false
anim1:Stop(0.5)
print("animation deactivated")
end
end
end)
the gui to the right shows the value repeating itself, I call the command to stop the animation & value the bool value listens than it goes back to the stage it was just in.