A few hours ago i've made a pistol script (keep in mind that for the pistol script i used mouse.Target) but i met a error along the way in which i can't figure out a solution, so basically a pistol has a cool down, right ? it won't just shoot out bullets like a rifle so i made a cool down IF the mouse.Target is either terrain or a player, but what about the sky, the sky is equal to nil, how do i add a cool down if my mouse is pointing at the sky ? (debounce just messes up the script)
local handle = script.Parent.Handle
local tool = script.Parent
local player = game.Players.LocalPlayer
local gui = player:WaitForChild("PlayerGui")
local screenGui = gui:WaitForChild("ScreenGui")
local TextLabel = screenGui:WaitForChild("Ammo")
local mouse = player:GetMouse()
local mxAm = 10
local Ammo1 = mxAm
local serivce = game:GetService("UserInputService")
local oldIcon = mouse.Icon
local function ammo2()
Ammo1 = mxAm
end
tool.Equipped:Connect(function()
mouse.Icon = "http://www.roblox.com/asset/?id=79658449"
TextLabel.Visible = true
end)
tool.Activated:Connect(function()
if tool.Enabled == true then
if Ammo1 > 0 then
Ammo1 = Ammo1 - 1
if mouse.Target.Parent:FindFirstChild("Humanoid") then
script.Parent.Damage:FireServer(mouse.Target)
tool.Enabled = false
print("target hit")
wait(0.2)
tool.Enabled = true
else
tool.Enabled = false
print("miss")
wait(0.2)
tool.Enabled = true
end
end
end
end)
while wait() do
TextLabel.Text = Ammo1.."/"..mxAm
tool.Unequipped:Connect(function()
mouse.Icon = oldIcon
TextLabel.Visible = false
end)
serivce.InputBegan:Connect(function(key)
if key.KeyCode == Enum.KeyCode.R and Ammo1 ~= mxAm then
wait(1)
ammo2()
end
end)
end

2 comments
thanks but i am getting errors saying: attempt to index nil with 'Text' and attempt to index nil with 'Visible'
i respect what you did but the gun breaks when you shoot at the sky, it just stops working :/