Hey. I want to do a Crouch System that when I press C it plays an Animation and when I press it again it stops playing the animation. It does play the animation but for some reason it doesn't stop it. No errors appear in the Output. The system is Filtering Enabled.
Script:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local crouchOnEvent = Instance.new("RemoteEvent", ReplicatedStorage)
crouchOnEvent.Name = "CrouchOnEvent"
local crouchOffEvent = Instance.new("RemoteEvent", ReplicatedStorage)
crouchOffEvent.Name = "CrouchOffEvent"
local animation = Instance.new("Animation")
animation.AnimationId = "http://roblox.com/asset/?id=1276087541"
local function onCrouchOnFired(plr)
local char = game.Workspace:FindFirstChild(plr.Name)
local humanoid = char.Humanoid
animTrack = humanoid:LoadAnimation(animation)
animTrack:Play()
end
crouchOnEvent.OnServerEvent:Connect(onCrouchOnFired)
local function onCrouchOffFired(plr)
local char = game.Workspace:FindFirstChild(plr.Name)
local humanoid = char.Humanoid
animTrack = humanoid:LoadAnimation(animation)
animTrack:Stop()
end
crouchOffEvent.OnServerEvent:Connect(onCrouchOffFired)
Local Script:
local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local crouchOnEvent = ReplicatedStorage:WaitForChild("CrouchOnEvent")
local crouchOffEvent = ReplicatedStorage:WaitForChild("CrouchOffEvent")
crouch = false
local function crouchOn(inputObject, gameProcessed)
if inputObject.KeyCode == Enum.KeyCode.C and crouch == false then
crouchOnEvent:FireServer()
crouch = true
end
end
UserInputService.InputBegan:Connect(crouchOn)
local function crouchOff(inputObject, gameProcessed)
if inputObject.KeyCode == Enum.KeyCode.C and crouch == true then
crouchOffEvent:FireServer()
crouch = false
end
end
UserInputService.InputBegan:Connect(crouchOff)

2 comments
Do animations on the client side I dont see why you need a server script to play them unless the model is iside workspace
Same. It doesn't stop it.