Hello, so im trying to make a semi gun, into an automatic. but i literally got no idea how, here is my script that is in the gun
--Object and Sound Variables
local gun = script.Parent
local gun_sound = game.ReplicatedStorage["Gun shot"]
local empty_sound = game.ReplicatedStorage.clip_empty
local reload_sound = game.ReplicatedStorage.Reload
local player = game.Players.LocalPlayer
local clipSize = gun.Ammo.Value
local ammo = gun.Ammo
local shooting = false
local equipped = false
--UserInputService Setup
local userInput = game:GetService('UserInputService')
--Mouse Icon
local mouse = game.Players.LocalPlayer:GetMouse()
--Remote Event Setup
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild('ShotEvent')
--Checks if Mouse is clicked
gun.Equipped:Connect(function(mouse)
player.PlayerGui.ScreenGui.Ammo.Visible = true
player.PlayerGui.ScreenGui.Ammo.Text = 'Ammo: ' .. tostring(ammo.Value) .. ' / ' .. tostring(gun.MaxAmmo.Value)
mouse.Button1Down:Connect(function()
if gun.Ammo.Value > 0 then
remoteEvent:FireServer(gun.Handle.Position, gun.Handle.Orientation, mouse.Hit.p)
gun_sound:Play()
gun.Ammo.Value -= 1
else
empty_sound:Play()
end
end
)
mouse.Button2Down:Connect(function()
local camera = game.Workspace.CurrentCamera
camera.FieldOfView = 40
end)
mouse.Button2Up:Connect(function()
local camera = game.Workspace.CurrentCamera
camera.FieldOfView = 70
end)
end)
-- Unequip gun
gun.Unequipped:Connect(function()
player.PlayerGui.ScreenGui.Ammo.Visible = false
end)
--Checks if the letter R is pressed to reload
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
if gun.Ammo.Value < clipSize and gun.MaxAmmo.Value > 0 then
reload_sound:Play()
reload_sound.Ended:Wait()
if gun.MaxAmmo.Value - (clipSize - gun.Ammo.Value) >= 0 then
gun.MaxAmmo.Value = gun.MaxAmmo.Value - (clipSize - gun.Ammo.Value)
gun.Ammo.Value = clipSize
else
gun.Ammo.Value = gun.Ammo.Value + gun.MaxAmmo.Value
gun.MaxAmmo.Value = 0
player.PlayerGui.ScreenGui.Ammo.Text = 'Ammo: ' .. tostring(ammo.Value) .. ' / ' .. tostring(gun.MaxAmmo.Value)
end
end
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)
local tool = -- tool
local Firing = false
tool.Activated:Connect(function()
Firing = true
while Firing do
-- OH BABY A TRIPLE KILL!
task.wait(60/RoundsPerMinute)
end
end)
tool.Deactivated:Connect(function()
Firing = false
end)
while shooting do
removeEvent:FireServer(gun.Handle.Position, gun.Handle.Orientation, mouse.Hit.p)
gun_sound:Play()
gun.Ammo.Value -= 1
end -- here
else
I have a feeling this is because of the fired server, try this to see if it outputs a warning
local gun = script.Parent
local gun_sound = game.ReplicatedStorage["Gun shot"]
local empty_sound = game.ReplicatedStorage.clip_empty
local reload_sound = game.ReplicatedStorage.Reload
local player = game.Players.LocalPlayer
local clipSize = gun.Ammo.Value
local ammo = gun.Ammo
local shooting = false
local equipped = false
--UserInputService Setup
local userInput = game:GetService('UserInputService')
--Mouse Icon
local mouse = game.Players.LocalPlayer:GetMouse()
--Remote Event Setup
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild('ShotEvent')
--Checks if Mouse is clicked
gun.Equipped:Connect(function(mouse)
player.PlayerGui.ScreenGui.Ammo.Visible = true
player.PlayerGui.ScreenGui.Ammo.Text = 'Ammo: ' .. tostring(ammo.Value) .. ' / ' .. tostring(gun.MaxAmmo.Value)
mouse.Button1Down:Connect(function()
while shooting do
if gun.Ammo.Value > 0 then
local success, err = pcall(function()
remoteEvent:FireServer(gun.Handle.Position, gun.Handle.Orientation, mouse.Hit.p)
gun_sound:Play()
gun.Ammo.Value -= 1
end)
if success then
print("fired")
else
warn(err)
end
else
empty_sound:Play()
end
task.wait(0.5)
end
end
)
mouse.Button2Down:Connect(function()
local camera = game.Workspace.CurrentCamera
camera.FieldOfView = 40
end)
mouse.Button2Up:Connect(function()
local camera = game.Workspace.CurrentCamera
camera.FieldOfView = 70
end)
end)
-- Unequip gun
gun.Unequipped:Connect(function()
player.PlayerGui.ScreenGui.Ammo.Visible = false
end)
--Checks if the letter R is pressed to reload
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
if gun.Ammo.Value < clipSize and gun.MaxAmmo.Value > 0 then
reload_sound:Play()
reload_sound.Ended:Wait()
if gun.MaxAmmo.Value - (clipSize - gun.Ammo.Value) >= 0 then
gun.MaxAmmo.Value = gun.MaxAmmo.Value - (clipSize - gun.Ammo.Value)
gun.Ammo.Value = clipSize
else
gun.Ammo.Value = gun.Ammo.Value + gun.MaxAmmo.Value
gun.MaxAmmo.Value = 0
player.PlayerGui.ScreenGui.Ammo.Text = 'Ammo: ' .. tostring(ammo.Value) .. ' / ' .. tostring(gun.MaxAmmo.Value)
end
end
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)