Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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

3 comments

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.

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.

0

It works now when the reload animation starts in one player, but still not when a player unequips or equips another weapon.

This discussion is preserved as it was. New answers, comments, and votes are closed.