Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why is my gun refusing to shoot?

Basically, I want my gun to shoot, but it refuses to! There are no errors too.

local Humanoid = game.Players.LocalPlayer.Character:WaitForChild("Humanoid")
local Tool = script.Parent
local Animation = nil
local SettingsFolder = Tool.Settings
local MagSize = SettingsFolder.MagSize
local MagsLeft = SettingsFolder.MagsLeft
local CurrentBullets = SettingsFolder.CurrentBullets
local Damage = SettingsFolder.Damage
local MouseDown = false
local IsReloading = false
local IsEquipped = false
local CanShoot = true
local Mouse = game.Players.LocalPlayer:GetMouse()

Tool.Equipped:Connect(function()
	Animation = Humanoid:LoadAnimation(game.ReplicatedStorage.AK80_Hold)
	Animation:Play()
	IsEquipped = true
end)

Tool.Unequipped:Connect(function()
	Animation:Stop()
	IsEquipped = false
end)

Tool.Activated:Connect(function()
	MouseDown = true
	repeat
		wait(0.01)
		Fire()
	until MouseDown == false
end)

Tool.Deactivated:Connect(function()
	MouseDown = false
end)

function Reload()
	IsReloading = true
	Tool.Reload:Play()
	Animation:Stop()
	Animation = Humanoid:LoadAnimation(game.ReplicatedStorage.AK80_Reload)
	Animation:Play()
	wait(2.27)
	CurrentBullets.Value = MagSize.Value
	MagsLeft.Value = MagsLeft.Value - MagSize.Value
	Animation:Stop()
	Animation = Humanoid:LoadAnimation(game.ReplicatedStorage.AK_Hold)
	Animation:Play()
	IsReloading = false
end

function Fire()
	if IsEquipped == true then
		if IsReloading == false then
			if CanShoot == true then
				if CurrentBullets.Value == not 0 then
					local ray = Ray.new(Tool.Handle.CFrame.p, (Mouse.Hit.p - Tool.Handle.CFrame.p).unit * 300)
					local touch, position = workspace:FindPartOnRay(ray, game.Players.LocalPlayer.Character, false, true)
					local trace = Instance.new("Part")
					trace.Anchored = trace
					trace.CanCollide = false
					trace.Transparency = 0.5
					trace.BrickColor = BrickColor.new("Electric blue")
					trace.Material = Enum.Material.Neon
					local distance = (Tool.Handle.CFrame.p + Vector3.new(0,0.6,0) - position).magnitude
					trace.Size = Vector3.new(0, 0, distance)
					trace.CFrame = CFrame.new(Tool.Handle.CFrame.p + Vector3.new(0,0.3,0), position) * CFrame.new(0, 0, -distance / 2)
					trace.Parent = workspace
					wait(0.1)
					trace:Destroy()
					Tool.Fire:Play()
					CurrentBullets.Value = CurrentBullets.Value - 1
					if touch then
						local humanoid = touch.Parent:FindFirstChild("Humanoid")
						if not humanoid then
							humanoid = touch.Parent.Parent:FindFirstChild("Humanoid")
						end
						if humanoid then
							humanoid:TakeDamage(Damage.Value)
						
				elseif CurrentBullets.Value == 0 and IsReloading == false and MagsLeft == not 0 then
					Reload()
				end					
				end
				end
			end
		end
	end
end

2 comments

0

In lines 57 and 82, you’re converting 0 to false.

0

Is the gun not shooting in studio, or ingame, or both?

2 answers

game.Players.LocalPlayer.Character:WaitForChild("Humano

Second line,maybe you didnt write "Humanoid" well

If your gun shoots in studio while testing, but not ingame, then it might be an FE issue. In FE, things like Instance.new wont go through, so you're going to have to use a RemoteEvent. Here's a tutorial on RemoteEvent; Tutorial

This discussion is preserved as it was. New answers, comments, and votes are closed.