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.