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)