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

The gun stops shooting after a couple shots, why is that? [SOLVED]

I have a script that gives the gun if you are on a certain team, when the player gets the gun, they can shoot multiple times after the gun stops working (on average 2), why is that? There are no errors in the output.

local script:

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()


script.Parent.Activated:Connect(function()
	game.ReplicatedStorage.ShootEvent:FireServer(Mouse.Target, Mouse.Hit.Position)

end)

server script:

local dbinterval = 0.5
db = false
game.ReplicatedStorage.ShootEvent.OnServerEvent:Connect(function(Player, MouseT, MouseP)
	if not db then
		db = true
	script.Parent.GunFlash.SurfaceLight.Enabled = true
	script.Parent.PistolSound:Play()
	wait(.1)
		script.Parent.GunFlash.SurfaceLight.Enabled = false
  if MouseT ~= nil then
			if MouseT:FindFirstAncestorOfClass("Model") ~= nil then
				if MouseT:FindFirstAncestorOfClass("Model"):FindFirstChild("Humanoid") then	
			MouseT:FindFirstAncestorOfClass("Model"):FindFirstChild("Humanoid"):TakeDamage(20)
		elseif db then
			wait(dbinterval)
			db = false
		end
		end
		end
		end
end)

1 answer

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