--localscript

local gunModel = script.Parent.Parent
local remoteEvent = gunModel.Gun:WaitForChild("RemoteEvent")

local currentPlayer, mouse, connection
local canFire = true

local cooldownTime = 0.25
local lastFireTime = 0

local function canFireCheck()
	return (tick() - lastFireTime >= cooldownTime)
end

local function fireRemoteEvent()
	if canFire then
		if canFireCheck() then
			lastFireTime = tick()

			if mouse.Target then
				remoteEvent:FireServer(mouse.Target)
			else
				print("invalid target")
			end

			canFire = false
			wait(cooldownTime)
			canFire = true
		end
	end
end

gunModel.Equipped:Connect(function()
	currentPlayer = game.Players.LocalPlayer
	mouse = currentPlayer:GetMouse()

	connection = gunModel.Activated:Connect(fireRemoteEvent)
end)

gunModel.Unequipped:Connect(function()
	if connection then
		connection:Disconnect()
	end

	currentPlayer, mouse, connection = nil
end)

--serverscript
local gun = script.Parent.Parent
local remoteEvent = gun.Gun:WaitForChild("RemoteEvent")
local gunshotSound = gun.Gun:WaitForChild("Shoot")

local HEADSHOT_DAMAGE = 78
local BODYSHOT_DAMAGE = 26
local LEGSHOT_DAMAGE = 13
local ARMSHOT_DAMAGE = 10

local function getCharacterFromPart(part)
	if not part then return nil end
	local character = part:FindFirstAncestorOfClass("Model")
	if character and character:FindFirstChild("Humanoid") then
		return character
	end
	return nil
end

local function handleShoot(player, targetPart, hitPosition)
	gunshotSound:Play()

	if not targetPart then return end

	local character = getCharacterFromPart(targetPart)
	if not character then return end

	local humanoid = character:FindFirstChild("Humanoid")
	if not humanoid or humanoid.Health <= 0 then return end

	local head = character:FindFirstChild("Head")
    local leftLeg = character:FindFirstChild("Left Leg")
    local rightLeg = character:FindFirstChild("Right Leg")
    local leftArm = character:FindFirstChild("Left Arm")
    local rightArm = character:FindFirstChild("Right Arm")
	local damage = BODYSHOT_DAMAGE

	if head and targetPart == head then
		damage = HEADSHOT_DAMAGE
    elseif leftLeg and targetPart == leftLeg then
        damage = LEGSHOT_DAMAGE
        humanoid.WalkSpeed = 12
    elseif rightLeg and targetPart == rightLeg then
        damage = LEGSHOT_DAMAGE
        humanoid.WalkSpeed = 12
    elseif leftArm and targetPart == leftArm then
--Unfinished
        damage = ARMSHOT_DAMAGE
	end

	humanoid:TakeDamage(damage)
    if not humanoid.Walkspeed == 12 then return end
end

remoteEvent.OnServerEvent:Connect(handleShoot)


-- Module Script

pistolCooldown = 0.25
hinderedPistolCooldown = 0.75

Embed on website

To embed this program on your website, copy the following code and paste it into your website's HTML: