Why aren't the if statements running?

I’m trying to make models drop from the crates, the if statements that clone the models aren’t running.

This is the script that I need help with

local health =  script.Parent:GetAttribute("Health")
local db = true
local module = require(script.Parent.RandomDrops)
local SawBlades = game.ServerStorage.SawBlades

script.Parent.Touched:Connect(function(hit)
	if hit.Name == "Handle" and db == true then
		db = false
		
		local damage = hit:GetAttribute("Damage")
		if damage == nil then
			print("Damage does not exist on this part")
			db = true
			return
		end
		health = health - damage
		script.Parent.Gui.hp.Text = health
		if health <= 0 then
			script.Parent.Gui.hp.Text = 0
			wait(.1)
			local chosen = module.Choose()
			print(chosen)
			if chosen == "0" then
				print("0")
				script.Parent:Destroy()
			elseif chosen == "PaperSaw" then
				print("Paper")
				local clone = SawBlades.PaperSaw:Clone()
				clone.Parent = game.Workspace
				clone.Position = Vector3.new(script.Parent.Position.X, script.Parent.Position.Y, script.Parent.Position.Z)
				script.Parent:Destroy()
			elseif chosen == "WoodenSaw" then
				print("Wooden")
				local clone = SawBlades.WoodenSaw:Clone()
				clone.Parent = game.Workspace
				clone.Position = Vector3.new(script.Parent.Position.X, script.Parent.Position.Y, script.Parent.Position.Z)
				script.Parent:Destroy()
			elseif chosen == "BronzeSaw" then
				print("bronze")
				local clone = SawBlades.BronzeSaw:Clone()
				clone.Parent = game.Workspace
				clone.Position = Vector3.new(script.Parent.Position.X, script.Parent.Position.Y, script.Parent.Position.Z)
				script.Parent:Destroy()
			elseif chosen == "IronSaw" then
				print("iron")
				local clone = SawBlades.IronSaw:Clone()
				clone.Parent = game.Workspace
				clone.Position = Vector3.new(script.Parent.Position.X, script.Parent.Position.Y, script.Parent.Position.Z)
				script.Parent:Destroy()
			end
		end
		wait(.7)
		db = true

	end
end)

This is the module scripting connecting to the script seen above.

local Drops = {}

Drops.DropList = {
	["Legendary"] = {game.ServerStorage.SawBlades.IronSaw};
	["Epic"] = {game.ServerStorage.SawBlades.BronzeSaw};
	["Rare"] = {game.ServerStorage.SawBlades.WoodenSaw};
	["Common"] = {game.ServerStorage.SawBlades.PaperSaw};
	["None"] = {0};

}

Drops.Chances = {
	["Legendary"] = 1;--%
	["Epic"] = 5;--%
	["Rare"] = 10;--%
	["Common"] = 25; --%
	["None"] = 59; -- %
}

Drops.Choose = function()

	local random = math.random(1,100)
	local count = 0

	for name, chance in pairs(Drops.Chances) do
		count = count + chance
		if random <= count then
			local DropNames = Drops.DropList[name]
			local chosen = DropNames[math.random(1,#DropNames)]

			return chosen
		end
	end
end

return Drops

I have no errors, the module is working correctly, when health hits 0 the code inside runs, the only problem is the if statements aren’t running.

1 Like

What does your output look like?

image

1 Like

its just showing the print(Chosen) above the script

1 Like

And not to judge your code, the way you did it works (well I mean it’s broken but not cause of the organization), but you could make it a lot shorter like this:

if chosen == "0" then
				print("0")
				script.Parent:Destroy()
			else
				print(Chosen)
				local clone = SawBlades.Chosen:Clone()
				clone.Parent = game.Workspace
				clone.Position = Vector3.new(script.Parent.Position.X, script.Parent.Position.Y, script.Parent.Position.Z)
				script.Parent:Destroy()

Then you don’t need any more if statements, just those 2

When it says print(chosen) before all the if statements, is that on line 23?

Edit cause I can’t post another reply:
Try adding an else statement that says what chosen is because it might be something else for some reason. Like nil or wrong capitalization.

1 Like