hello all, me and my friend made a gun system, and every gun is just a single shot but i want to to auto Aswell, i tried doing the
local holding = false
mouse.Button1Down:Connect(function()
holding = true
end)
mouse.Button1Up:Connect(function()
holding = false
end)
and it still functions like a regular single shot gun.
here is the source code if you need it
local player = game:GetService("Players").LocalPlayer
local mouse = player:GetMouse()
local mouseHold = false
local shooting = false
local serverRemote = script.Parent:WaitForChild("Events").Shoot
local shootAnim = script.Parent.Animations.Shoot
local Animation = script.Parent.Animations.Idle
local equipAnimation = script.Parent.Animations.Equip
local uis = game:GetService("UserInputService")
local CD = false
local function testFire()
local direction = mouse.Hit.Position
local LoadAnimation = player.Character:WaitForChild("Humanoid"):LoadAnimation(shootAnim)
local reloadANimation = script.Parent.Animations.Reload
loadReloadForFire = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(reloadANimation)
serverRemote:FireServer(direction)
LoadAnimation:Play()
if loadReloadForFire.IsPlaying then
loadReloadForFire:Stop()
end
script.Parent.Sounds["Shoot"]:Play()
print("bullet has been shot")
print(direction)
end
mouse.Button1Down:Connect(function(MouseSource)
mouseHold = true
if script.Parent.IsEquipped.Value == true and CD == false and mouseHold == true then
if script.Parent.Stats.Ammo.Value > 0 then
--CD = true
testFire()
--wait(0.1)
--CD = false
end
uis.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.R then
if script.Parent.Stats.Ammo.Value < script.Parent.Stats.Mag.Value then
script.Parent.Events.Reload:FireServer()
local reloadANimation = script.Parent.Animations.Reload
loadReload = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(reloadANimation)
loadReload:Play()
script.Parent:WaitForChild("Sounds").Reload:Play()
end
end
end)
end
end)
mouse.Button1Up:Connect(function()
mouseHold = false
end)
local function OnEquip()
animation = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(Animation)
equipanimation = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(equipAnimation)
equipanimation:Play()
mouse.Icon = "rbxassetid://409468479"
if equipanimation.Stopped then
animation:Play()
end
script.Parent.IsEquipped.Value = true
script.Parent.Sounds["Equip"]:Play()
end
local function OnUnequip()
animation:Stop()
equipanimation:Stop()
loadReload:Stop()
mouse.Icon = "rbxassetid://"
script.Parent:WaitForChild("Sounds").Reload:Stop()
local activeTracks = player.Character.Humanoid:GetPlayingAnimationTracks()
for _,v in pairs(activeTracks) do
v:Stop()
end
end
script.Parent.Equipped:Connect(function()
OnEquip()
end)
script.Parent.Unequipped:Connect(function()
OnUnequip()
end)