I'm making a game, and there's a gun in it that doesn't have an animation for recoil. I attempted to add one, but now the gun doesn't work at all. I've added the animation into the gun, named it Recoil and gave it the AnimationId, but it doesn't work at all.
Here is the script I'm using:
local gun = script.Parent
local gun_sound = gun.Handle['Gun shot']
local empty_sound = gun.Handle.clip_empty
local reload_sound = gun.Handle.Reload
local player = game.Players.LocalPlayer
local clipSize = gun:WaitForChild('Ammo').Value
local ammo = gun:WaitForChild('Ammo')
local Recoil_Anim = gun.WaitForChild('Recoil')
--UserInputService Setup
local userInput = game:GetService('UserInputService')
--Mouse Icon
local mouse = game.Players.LocalPlayer:GetMouse()
mouse.Icon = 'rbxassetid://316279304'
local ReplicatedStorage = game:GetService('ReplicatedStorage')
local remoteEvent = ReplicatedStorage:WaitForChild('ShotEvent')
gun.Equipped:Connect(function(mouse)
player.PlayerGui.ScreenGui.Ammo.Visible = true
player.PlayerGui.ScreenGui.Ammo.Text = 'Ammo:' .. tostring(ammo.Value) ..' / ' .. tostring(gun.MaxAmmo.Value)
gun.Unequipped:Connect(function()
player.PlayerGui.ScreenGui.Ammo.Visible = false
end)
mouse.Button1Down:Connect(function()
if gun.Ammo.Value > 0 then
remoteEvent:FireServer(gun.Handle.Position, mouse.Hit.p)
Recoil_Anim:Play()
gun_sound:Play()
gun.Ammo.Value = gun.Ammo.Value - 1
else
reload_sound:Play()
reload_sound.Ended:Wait()
gun.Ammo.Value = 12
end
end)
end)
--Checks if the Letter R is pressed
userInput.InputBegan:Connect(function(input, gameProcessed)
if not gameProcessed then
if input.UserInputType == Enum.UserInputType.Keyboard or input.UserInputType == Enum.UserInputType.Gamepad1 then
local keycode = input.KeyCode
if keycode == Enum.KeyCode.R or keycode == Enum.KeyCode.ButtonX then
reload_sound:Play()
reload_sound.Ended:Wait()
gun.Ammo.Value = 12
end
end
end
end)
--Update ammo GUI
ammo.Changed:Connect(function()
player.PlayerGui.ScreenGui.Ammo.Text = 'Ammo:' .. tostring(ammo.Value) ..' / ' .. tostring(gun.MaxAmmo.Value)
end)

2 comments
did u have put on ur output? if u put ur output on u can exactly see what the problem is.
I put it on output and nothing happened.