I have a script that plays animations on the client, and fires a remote event to play them on the server as well. However, when my animations are played, they are also played every other players character on my screen, as though something is telling ALL characters to play this animation. Does anyone know what could be causing this? Thank you tons in advance.
(Rather than someone combing through like 300 lines, I was hoping someone could suggest a possible issue to look for? Could it be something to do with the remote events which are stored plainly in replicatedstorage?)
local Pawn = game:GetService("Players").LocalPlayer local mouse = Pawn:GetMouse() local character = Pawn.Character if not character or not character.Parent then character = Pawn.CharacterAdded:wait() end local Anim = Instance.new("Animation") local grounded = false local already_ran = false ---------------Assets and Events---------- local Idle =("rbxassetid://661054611") local Walk = ("rbxassetid://661645004") local CombatIdle =("rbxassetid://658368358") local CombatWalk = ("rbxassetid://658801474") local CombatSprint = ("rbxassetid://671718470") local DodgeBack = ("rbxassetid://671817732") local Sprint = ("rbxassetid://662016268") local Left_Swing = ("rbxassetid://662302773") local Left_Swing2 = ("rbxassetid://671753749") local Right_Swing = ("rbxassetid://662302773") local Central_Swing = ("rbxassetid://672013731") local Central_Swing2 = ("rbxassetid://672013731") local Sheathe = ("rbxassetid://664055993") local Unsheathe = ("rbxassetid://664054478") local Walkspeed = 14 local SprintEvent = game.ReplicatedStorage:WaitForChild("SprintEvent") local SheatheEvent = game.ReplicatedStorage:WaitForChild("SheatheEvent") local UnSheatheEvent = game.ReplicatedStorage:WaitForChild("UnSheatheEvent") local DodgeEvent = game.ReplicatedStorage:WaitForChild("DodgeEvent") local FootSmoke = game.ReplicatedStorage:WaitForChild("FootSmoke") local Animate = game.ReplicatedStorage:WaitForChild("AnimateEvent") -----------Global Functions----------- function PlayAnim(parent) local AnimTrack = character.Humanoid:LoadAnimation(Anim) for _,anim in pairs(character.Humanoid:GetPlayingAnimationTracks()) do anim:Stop() break end wait(.01) AnimTrack:Play() AnimTrack:AdjustSpeed(1) end function PlayAnim2(parent) local AnimTrack = character.Humanoid:LoadAnimation(Anim) AnimTrack:Play() AnimTrack:AdjustSpeed(1) end function ChangeStance(Value) script.CombatStance.Value = Value end ---------------Movement Functionality----------------------- function onGround(speed) if grounded == false then print("Grounded") grounded = true end if speed > 1 and script.CombatStance.Value == ("Explorative") and script.Sprinting.Value == false then if already_ran == false then already_ran = true Anim.AnimationId = (Walk) PlayAnim(Anim) Animate:FireServer(Walk) print("Runnin!") end elseif speed > 1 and script.CombatStance.Value == ("Combative") and script.Sprinting.Value == false then if already_ran == false then already_ran = true Anim.AnimationId = (CombatWalk) PlayAnim(Anim) Animate:FireServer(CombatWalk) FootSmoke:FireServer(false) end elseif speed > 1 and script.CombatStance.Value == ("Explorative") and script.Sprinting.Value == true then if already_ran == false then already_ran = true Anim.AnimationId = (Sprint) PlayAnim(Anim) Animate:FireServer(Sprint) FootSmoke:FireServer(true) end elseif speed > 0 and already_ran == true and script.CombatStance.Value == ("Explorative") then already_ran = false Anim.AnimationId = (Idle) PlayAnim(Anim) Animate:FireServer(Idle) FootSmoke:FireServer(false) elseif speed > 0 and already_ran == true and script.CombatStance.Value == ("Combative") then already_ran = false Anim.AnimationId = (CombatIdle) Animate:FireServer(CombatIdle) PlayAnim(Anim) end end character.Humanoid.Running:connect(onGround) ---------------------Input Events------------------------ function onKeyPress(inputObject, gameProcessedEvent) if inputObject.KeyCode == Enum.KeyCode.LeftShift and script.Sprinting.Value == (false) and script.CombatStance.Value == ("Explorative") then script.Sprinting.Value = (true) Walkspeed = 36 SprintEvent:FireServer(Walkspeed) elseif inputObject.KeyCode == Enum.KeyCode.LeftShift and script.Sprinting.Value == (true) then script.Sprinting.Value = (false) Walkspeed = 20 SprintEvent:FireServer(Walkspeed) elseif inputObject.KeyCode == Enum.KeyCode.C and script.CombatStance.Value == ("Explorative") then script.CombatStance.Value = ("Combative") Anim.AnimationId = (Unsheathe) PlayAnim(Anim) Animate:FireServer(Unsheathe) UnSheatheEvent:FireServer(0) wait(1) Walkspeed = 20 script.Sprinting.Value = false SprintEvent:FireServer(Walkspeed) Animate:FireServer(CombatIdle) Anim.AnimationId = (CombatIdle) PlayAnim(Anim) elseif inputObject.KeyCode == Enum.KeyCode.C and script.CombatStance.Value == ("Combative") then script.CombatStance.Value = ("Explorative") Anim.AnimationId = (Sheathe) PlayAnim(Anim) Animate:FireServer(Sheathe) SheatheEvent:FireServer(0) wait(1) SprintEvent:FireServer(Walkspeed) Anim.AnimationId = (Idle) PlayAnim(Anim) Animate:FireServer(Idle) elseif inputObject.KeyCode == Enum.KeyCode.T and script.CombatStance.Value == ("Combative") then script.CombatStance.Value = ("Tools") Anim.AnimationId = (Sheathe) PlayAnim(Anim) Animate:FireServer(Sheathe) SheatheEvent:FireServer(0) wait(1) SprintEvent:FireServer(Walkspeed) Anim.AnimationId = (Idle) PlayAnim(Anim) Animate:FireServer(Idle) elseif inputObject.KeyCode == Enum.KeyCode.R and script.CombatStance.Value == ("Combative") then Anim.AnimationId = (DodgeBack) PlayAnim(Anim) Animate:FireServer(DodgeBack) DodgeEvent:FireServer(0) wait(0.7) SprintEvent:FireServer(Walkspeed) Anim.AnimationId = (CombatIdle) Animate:FireServer(CombatIdle) PlayAnim(Anim) elseif inputObject.KeyCode == Enum.KeyCode.F then script.SwingDirection.Value = ("Left") script.AttackCoolDown.Value = (0) elseif inputObject.KeyCode == Enum.KeyCode.G then script.SwingDirection.Value = ("Central") script.AttackCoolDown.Value = (0) elseif inputObject.KeyCode == Enum.KeyCode.H then script.SwingDirection.Value = ("Right") script.AttackCoolDown.Value = (0) end end game:GetService("UserInputService").InputBegan:connect(onKeyPress) mouse.Button1Down:connect(function() if script.CombatStance.Value == ("Combative") and script.SwingVariant.Value == ("First") and script.SwingDirection.Value == ("Left") and script.AttackCoolDown.Value == (0) then script.SwingVariant.Value = ("Second") script.AttackCoolDown.Value = 2 Anim.AnimationId = (Left_Swing) PlayAnim2(Anim) Animate:FireServer(Left_Swing) print("Attacking") wait(1) script.AttackCoolDown.Value = 0 elseif script.CombatStance.Value == ("Combative") and script.SwingVariant.Value == ("Second") and script.SwingDirection.Value == ("Left") and script.AttackCoolDown.Value == (0) then script.SwingVariant.Value = ("First") script.AttackCoolDown.Value = 2 Anim.AnimationId = (Left_Swing2) Animate:FireServer(Left_Swing2) PlayAnim2(Anim) print("Attacking") wait(1) script.AttackCoolDown.Value = 0 elseif script.CombatStance.Value == ("Combative") and script.SwingVariant.Value == ("First") and script.SwingDirection.Value == ("Central") and script.AttackCoolDown.Value == (0) then script.SwingVariant.Value = ("Second") script.AttackCoolDown.Value = 2 Anim.AnimationId = (Central_Swing) Animate:FireServer(Central_Swing) PlayAnim2(Anim) print("Attacking") wait(1) script.AttackCoolDown.Value = 0 elseif script.CombatStance.Value == ("Combative") and script.SwingVariant.Value == ("Second") and script.SwingDirection.Value == ("Central") and script.AttackCoolDown.Value == (0) then script.SwingVariant.Value = ("First") script.AttackCoolDown.Value = 2 Anim.AnimationId = (Central_Swing2) Animate:FireServer(Central_Swing2) PlayAnim2(Anim) print("Attacking") wait(1) script.AttackCoolDown.Value = 0 end end) --SERVER STUFF local Pawn = script.Parent local Anim = Instance.new("Animation") function playAnimation(parent) local AnimTrack = Pawn.Humanoid:LoadAnimation(Anim) AnimTrack:Stop() wait(.01) AnimTrack:Play() AnimTrack:AdjustSpeed(1) end Animate.OnServerEvent:connect(function(player,AnimationStyle) -- OnServerEvent automatically passes the player who fired it as the first argument. for _,anim in pairs(Pawn.Humanoid:GetPlayingAnimationTracks()) do anim:Stop() break end Anim.AnimationId = (AnimationStyle) playAnimation(Anim) end)
ok, im not sure if this is correct but i will try, in line 4 put if Pawn.Name == "Yourname" then