So I don't really care if the value is nil, but whenever I click in a nil area I want it to print() but it won't print! It just gives me an error! Here's the code:

local Player = game.Players.LocalPlayer -- The Player
local DB = false -- Debounce
local Char = Player.Character -- Player's Character
local VariableTest = "Variable test" -- Test
local mouse = Player:GetMouse() -- The mouse
local Tool = script.Parent -- The tool
local Player = game.Players.LocalPlayer -- Player2
local Char = Player.Character -- Char2
local ReplicatedStorage = game:GetService("ReplicatedStorage") -- ReplicatedStorage -- FireEvent
local player = game.Players.LocalPlayer -- Player3
local mouse = player:GetMouse() -- Mouse2
local maxAmmo = 30 -- MaxAmmo
local ammo = maxAmmo -- MaxAmmo2
local rate = 60/850 -- FireRate. Don't touch the 60!!!!!!!!!!
local Canfire = true -- By default true
local reload = 1.5 -- Reload Time
local reloading = false
local UIS = game:GetService("UserInputService")
local damage = math.random(15,25) -- Damage
game.StarterGui.ScreenGui.Frame.TextLabel.Text = ammo


Tool.Equipped:Connect(function()
	script.Parent.Activated:Connect(function()
		game.StarterGui.ScreenGui.Frame.TextLabel.Text = ammo
		if ammo >= 1 and firing == false and Canfire == true and reloading == false then
			firing = true
			repeat
		local player = game.Players.LocalPlayer or game.Players.PlayerAdded:Wait() -- Camera-Shake stuff
local char = player.Character or player.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid") 
local A = math.random(-0.1, 0.1)
    hum.CameraOffset = hum.CameraOffset + Vector3.new(0,A,0.1)
wait(0.01)
hum.CameraOffset = hum.CameraOffset - Vector3.new(0,A,0.1)
Tool.FlamePart.Transparency = 0 -- Flash effects
wait(0.000001) -- Wait Time for Flash FX
Tool.FlamePart.Transparency = 1
				script.Parent.M4A1:Play()
				print(ammo)
				wait(rate)
				ammo = ammo - 1
			until ammo < 1 or firing == false

(I have more code than this but all I need is the thing to print)

7 comments

0

Why would you need to check if they're not clicking on the player?

0

Oop. Lemme show the rest of the code.

0

There

0

Where are you using mouse.Target

0

mouse.Target will be nil when the mouse is not hitting a part. Use mouse.Hit.p if you just want to get the hit position. if you want to get the part, check if mouse.Target exists: if mouse.Target then

0

Oh thanks!

0

Nope. Doesn't work