Sorry I posted it wrong.
Your script works but I still can reload the gun. I didnt show all script but I can show just for understand.
script:
--------Varibles--------
local plr = game:GetService(“Players”).LocalPlayer
local tool = script.Parent
local anim
local Shoot
local reload
local ScopeAim
local Gun_Sound = script.Parent:WaitForChild(“SniperShoot”)
local Empty_Sound = script.Parent:WaitForChild(“EmptyGunSound”)
local Reload_Sound = script.Parent:WaitForChild(“ReloadGunSound”)
local clipSize = tool:WaitForChild(“Ammo”).Value
local ammo = tool:WaitForChild(“Ammo”)
local button1DownListener = nil
local button2DownListener = nil
local button2UpListener = nil
local debounce = false
--------Animations--------
tool.Equipped:Connect(function()
local char = plr.Character or plr.CharacterAdded:Wait()
game.ReplicatedStorage.ConnectM6D:FireServer(tool.BodyAttach)
char.Torso.ToolGrip.Part0 = char.Torso
char.Torso.ToolGrip.Part1 = tool.BodyAttach
local Humanoid = char:FindFirstChild('Humanoid')
anim = Humanoid:LoadAnimation(script:WaitForChild("Idle"))
Shoot = Humanoid:LoadAnimation(script:WaitForChild("Shoot"))
reload = Humanoid:LoadAnimation(script:WaitForChild("Reload"))
ScopeAim = Humanoid:LoadAnimation(script:WaitForChild("Aim"))
anim:Play()
end)
tool.Unequipped:Connect(function()
game.ReplicatedStorage.DisconnectM6D:FireServer()
if not anim then return end
anim:Stop()
reload:Stop()
ScopeAim:Stop()
end)
--------UserInputService Setup--------
local userInput = game:GetService(“UserInputService”)
--------Mouse Icon--------
local mouse = game.Players.LocalPlayer:GetMouse()
mouse.Icon = “rbxassetid://117431027”
--------Remote Event Setup--------
local ReplicatedStorage = game:GetService(“ReplicatedStorage”)
local RemoteEvent = ReplicatedStorage:WaitForChild(“ShootEvent”)
--------Checks if Mouse is Clicked--------
tool.Equipped:Connect(function(Mouse)
if not debounce then
plr.PlayerGui.AmmoGui.Enabled = true
plr.PlayerGui.AmmoGui.AmmoText.Text = "Ammo: "… tostring(ammo.Value) … “/” … tool.MaxAmmo.Value
button1DownListener = Mouse.Button1Down:Connect(function()
if tool.Ammo.Value > 0 then
debounce = true
RemoteEvent:FireServer(tool.BulletLocation.Position, tool.BulletLocation.Orientation, Mouse.Hit.p)
Gun_Sound:Play()
Shoot:Play()
tool.Ammo.Value = tool.Ammo.Value - 1
else
Empty_Sound:Play()
Shoot:Play()
end
end)
button2DownListener = mouse.Button2Down:Connect(function()
local camera = game.Workspace.CurrentCamera
ScopeAim:Play()
camera.FieldOfView = 10
end)
button2UpListener = mouse.Button2Up:Connect(function()
local camera = game.Workspace.CurrentCamera
camera.FieldOfView = 70
ScopeAim:Stop()
end)
end
end)
--------Unequip gun--------
tool.Unequipped:Connect(function()
plr.PlayerGui.AmmoGui.Enabled = false
debounce = false
if button1DownListener then
button1DownListener:Disconnect()
button1DownListener = nil
end
if button2DownListener then
button2DownListener:Disconnect()
button2DownListener = nil
end
if button2UpListener then
button2UpListener:Disconnect()
button2UpListener = nil
end
end)
--------Checks if the letter R is pressed for reload-------- (Here is the reload function)
userInput.InputBegan:Connect(function(input, gameProcessed)
if not gameProcessed then
if input.UserInputType == Enum.UserInputType.Keyboard then
local keycode = input.KeyCode
if keycode == Enum.KeyCode.R then
reload:Play()
Reload_Sound:Play()
Reload_Sound.Ended:Wait()
tool.Ammo.Value = 7
end
end
end
end)
--------Update ammo GUI--------
ammo.Changed:Connect(function()
plr.PlayerGui.AmmoGui.AmmoText.Text = "Ammo: "… tostring(ammo.Value) … “/” … tool.MaxAmmo.Value
end)