Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Starting an animation in one player prompts another to stop in a different player?

Asked by 5 years ago

So, basically I am working on a FPS game, and I made a custom tool system of my own. Now, for whatever reason ( not sure if this was happening before I switched or not ), when a player switches to a different weapon, all the other players' animations stop. I've tested this in a live game and in studio.

This is the code in a server script. There's nothing wrong on the client end, trust me lol.

replicatedStorage.Weapons.Melee.MeleeSwingEvent.OnServerEvent:Connect(function(player, tool, animation)
    local fireAnim = tool.Parent.Humanoid:LoadAnimation(animation)
    fireAnim:Play()
    tool.WeaponDetails.Swinging.Value = true
    tool.FireSound:Play()
end)

replicatedStorage.Weapons.EquipAnimation.OnServerEvent:Connect(function(player,animation, idleAnimation, tool)
    local newAnim = workspace[player.Name].Humanoid:LoadAnimation(animation)
    newAnim:Play()
    local idleAnimationLoaded = workspace[player.Name].Humanoid:LoadAnimation(idleAnimation)
    idleAnimationLoaded:Play()
    tool.EquipSound:Play()

    replicatedStorage.Weapons.UnequipAnimation.OnServerEvent:Connect(function(player)
        newAnim:Stop()
        idleAnimationLoaded:Stop()
        for i,v in pairs(workspace:GetChildren()) do
            if v.Name == player.Name.."'s Trajectory" then
                v:Destroy()
            end
        end
    end)

    replicatedStorage.Weapons.Reload.OnServerEvent:Connect(function(player,animation)
        if animation.Parent.ReloadSound.Playing == false then
            animation.Parent.ReloadSound:Play()
            local reloadAnim = workspace[player.Name].Humanoid:LoadAnimation(animation)
            reloadAnim:Play()
        end
    end)
end)

1 answer

Log in to vote
0
Answered by
T1mes 230 Moderation Voter
5 years ago
Edited 5 years ago

Your problem might be that

replicatedStorage.Weapons.Melee.MeleeSwingEvent.OnServerEvent:Connect(function(player, tool, animation)
    local fireAnim = tool.Parent.Humanoid:LoadAnimation(animation)
    fireAnim:Play()
    tool.WeaponDetails.Swinging.Value = true
    tool.FireSound:Play()
end)

replicatedStorage.Weapons.EquipAnimation.OnServerEvent:Connect(function(player,animation, idleAnimation, tool)
    local newAnim = workspace[player.Name].Humanoid:LoadAnimation(animation)
    newAnim:Play()
    local idleAnimationLoaded = workspace[player.Name].Humanoid:LoadAnimation(idleAnimation)
    idleAnimationLoaded:Play()
    tool.EquipSound:Play()
-- you're missing some ends here
--[[ replicatedStorage.Weapons.UnequipAnimation.OnServerEvent:Connect(function(player)
        newAnim:Stop()
        idleAnimationLoaded:Stop()
        for i,v in pairs(workspace:GetChildren()) do
            if v.Name == player.Name.."'s Trajectory" then
                v:Destroy()
            end
        end
    end)

    replicatedStorage.Weapons.Reload.OnServerEvent:Connect(function(player,animation)
        if animation.Parent.ReloadSound.Playing == false then
            animation.Parent.ReloadSound:Play()
            local reloadAnim = workspace[player.Name].Humanoid:LoadAnimation(animation)
            reloadAnim:Play()
        end
    end)
end) Meaning that you're connecting all of this.]]

Try reconnecting the events with their proper endings and do NOT use the code above, for I commented most of it rendering it useless

0
I'm confused of what you're talking about here. If the player switches off the weapon, the holding animation HAS to stop so I can't just disconnect those. Protori 0 — 5y
0
I'm not saying do what I did, i'm saying all that I highlighted is connected due to some ends being in the wrong place. T1mes 230 — 5y
0
It works now when the reload animation starts in one player, but still not when a player unequips or equips another weapon. Protori 0 — 5y
Ad

Answer this question