How to make an else that just outputs nothing?

I have a script which waits till you have an tool/item equipped yet I don’t want it to release an error or nil if there’s nothing there so is there a way to do something like

else 
     print("")

Which would send nothing?
My current script is :

local module = {}

function module.SpecialHell(player)
	for i,v in pairs(game.Players:GetChildren()) do
		local tool = v.Character["Real Knife"]
		if tool.Name == "Real Knife" then
			print("test", player.Name)
		else
			print("")
		end
	end
end

function module.RealSlash(player)
	for i,v in pairs(game.Players:GetChildren()) do
		local tool = v.Character["Real Knife"]
		if tool.Name == "Real Knife" then
			print("test", player.Name)
		else
			print("")
		end
	end
end

return module

I’m pretty sure it doesn’t work since it is looking for the tool first, But I don’t know how else to do it.

Since upon both occasions they occur in a loop, use the continue keyword to continue to the next loop iteration

Like this?

local module = {}

function module.SpecialHell(player)
	for i,v in pairs(game.Players:GetChildren()) do
		local tool = v.Character["Real Knife"]
		if tool.Name == "Real Knife" then
			print("test", player.Name)
		else
			continue
		end
	end
end

function module.RealSlash(player)
	for i,v in pairs(game.Players:GetChildren()) do
		local tool = v.Character["Real Knife"]
		if tool.Name == "Real Knife" then
			print("test", player.Name)
		else
			continue)
		end
	end
end

return module

So it wouldn’t end in an error?

No it still will because the way you setup your code does not prevent errors, you first try to get the tool from the player (when it doesn’t exist that line errors) THEN you check if the tools name is equal to the, well, the tools name.

It should be like this:

local module = {}

function module.SpecialHell(player)
	for i,v in pairs(game.Players:GetChildren()) do
        local char = v.Character or v.CharacterAdded:Wait()
		if char:FindFirstChild("Real Knife") then
            local tool = char:FindFirstChild("Real Knife")
			print("test", player.Name)
		else
			continue
		end
	end
end

function module.RealSlash(player)
	for i,v in pairs(game.Players:GetChildren()) do
        local char = v.Character or v.CharacterAdded:Wait()
		if char:FindFirstChild("Real Knife") then
            local tool = char:FindFirstChild("Real Knife")
			print("test", player.Name)
		else
			continue
		end
	end
end

return module
2 Likes

Oh awesome it works thank you so much!! : D