Crouch Animation Plays for Anyone Holding Tool Instead of Just Client

I have a local script that gets once the player has pressed “C” and then fires a remote event to play an animation that makes player crouch. However when I press C if there are 2 players holding a gun in the game at once, they both end up having the crouch animation play even if only 1 client pressed it.

Example of Error:
https://gyazo.com/87e2206406b05ffeff4b22a0e0fe1db2

– Local Script

local UserInputService = game:GetService("UserInputService")
local RepStore = game.ReplicatedStorage

local function onInputBegan(input, gameProcessed)
	local Plr = game.Players.LocalPlayer
	if input.KeyCode == Enum.KeyCode.C then
		RepStore.Crouch:FireServer(Plr)
		
	end
end

UserInputService.InputBegan:Connect(onInputBegan)

– Server Script

local Tool = script.Parent
local Animation = Tool.Animation
local Frame = script.Parent.Frame
local RepStore = game.ReplicatedStorage


Tool.Equipped:Connect(function()
	local Character = Tool.Parent
	local Humanoid = Character.Humanoid

	local AnimationTrack = Humanoid:LoadAnimation(Animation)


	local clFR = Frame:Clone()
	clFR.Parent = game.Players.vinceops.PlayerGui.ScreenGui
	Animation.AnimationId = "rbxassetid://10150787038"
	AnimationTrack:Play()
	
			Tool.Unequipped:Connect(function()
				Animation.AnimationId = "rbxassetid://10150787038"
				AnimationTrack:Stop()
				clFR:Destroy()
			end)
end)





RepStore.Crouch.OnServerEvent:Connect(function(Plr)
	local Character = Tool.Parent
	local Humanoid = Character.Humanoid
	local AnimationTrack = Humanoid:LoadAnimation(Animation)

	Animation.AnimationId = "rbxassetid://10151060980"
	Plr.Character.Humanoid.WalkSpeed = 10
	AnimationTrack:Play()
	wait(2)
	AnimationTrack:Stop()
	Animation.AnimationId = "rbxassetid://10150787038"
	Plr.Character.Humanoid.WalkSpeed = 16
	AnimationTrack:Play()
end)

What I want:

Just the player that fires the event to crouch, rather than anyone holding the tool at the same time.

Maybe put out your server script into localScript. Without remote events. Animation should play and everyone should see this animation instead of playing animation for multiple players.

1 Like

Wait so if I run an animation through a local script, everyone can see it?

Yes. (ignore hshhshs)

1 Like

Player animation get’s replicated to the server, so just use your local script.

1 Like
RepStore.Crouch:FireServer(Plr)

Every client is currently sharing the same RemoteEvent, additionally you’re explicitly passing a player argument to FireServer().