I just feel like this script is... Nasty

-- \\ Get-Services Variables // --

local RS = game:GetService("ReplicatedStorage")

local CS = game:GetService("CollectionService")

local SP = game:GetService("StarterPack")

local VFX = RS.Misc.VFX

-- \\ RS Variables // --

local Mine = script.Parent.Minin

local Health = 1

local DB = false
-- \\ Tools // --

local HEAD = SP.Pickaxe.PickHead

local RockConfig = workspace.Rock.RockConfig
-- \\ Functions // -- 

local connect
connect = Mine.OnServerEvent:Connect(function(plr)
	local Pickaxe = plr.Character:FindFirstChild("Pickaxe")
	local Head = Pickaxe:FindFirstChild("PickHead")
		if Head then
			Head.Touched:Connect(function(Hit)
				if CS:HasTag(Hit, "Ores") then 
					if DB == false then
						DB = true
					local HP = RockConfig.HP
					HP.Value = HP.Value-1
					VFX:FireClient(plr, "CombatVFXHandler", "Mine", Head)
						if HP.Value <= 0 then
							_G.RockBreaking()
						connect:Disconnect()
					end
						task.wait(2)
						DB = false
					end
				end
			end)
		end
end)

The functionally is simple enough, I have a seperate block script that randomizes the ore type and once you break it, you have a rock. Yet, something feels… Off or nasty about it, same thing with the randomziation script.

Ran. Script:

-- // I'm lazy as shit // --

local Ore = script.Parent

local RS = game:GetService("ReplicatedStorage")

local TW = require(RS.Modules.TweenModule)

local TWS = game:GetService("TweenService")

local Rocks = RS.RealROCK:Clone()

local CS = game:GetService("CollectionService")

local Transparency, Size, Position 
-- // Config \\ --

local OreTypes = {"Rock", "Copper", "Bronze"}
local Cooldowns = {20, 40, 60}
local DropAmount 
local DropMax = {3, 2, 1}
local DropMin = {2, 1, 1}
local HP = {5, 10, 20}
local OreColor = {Color3.new(91, 93, 105), Color3.new(160, 95, 53), Color3.new(90, 76, 66)}
local Chances = {Rock = 0.50, Copper = 0.25, Bronze = 0.15}
local Weight = 0
local Config = script.Parent.RockConfig
-- \\ Functions // --

if CS:HasTag(Ore, "Ores") then
	print("AUGHhh")
end


local function Randomization()
	for _, Chance in pairs(Chances) do
	--	print("Rolling")
		Weight += (Chance * 10)
		print(Weight)
	end
	local ranNumber = math.random(1, Weight)
	--print("Got it")
	Weight = 0
	for Rock, Chance in pairs(Chances) do
		--print("Just debugging")
		Weight += (Chance * 10)
		print(Weight)
		--print("Still bugging")
		if Weight >= ranNumber then
			print("Rock Spawned, it's a ".. Rock)
			Ore:SetAttribute("OreTypes", Rock)
			break
			
		end
	end 	
end

local function SettingUp()
	
	if Ore:GetAttribute("OreTypes") == OreTypes[1] then
		Config.Cooldown.Value = Cooldowns[1]
		Config.DropMax.Value = DropMax[1]
		Config.DropMin.Value = DropMin[1]
		Config.HP.Value = HP[1]
		Config.OreColor.Value = OreColor[1]
		Config.OreTypes.Value = OreTypes[1]
		Ore.Color = Config.OreColor.Value
		print("It's a rock.")
	elseif Ore:GetAttribute("OreTypes") == OreTypes[2] then
		Config.Cooldown.Value = Cooldowns[2]
		Config.DropMax.Value = DropMax[2]
		Config.DropMin.Value = DropMin[2]
		Config.HP.Value = HP[2]
		Config.OreColor.Value = OreColor[2]
		Config.OreTypes.Value = OreTypes[2]
		Ore.Color = Config.OreColor.Value
		print("It's a Copper.")
	elseif Ore:GetAttribute("OreTypes") == OreTypes[3] then
		
		Config.Cooldown.Value = Cooldowns[3]
		Config.DropMax.Value = DropMax[3]
		Config.DropMin.Value = DropMin[3]
		Config.HP.Value = HP[3]
		Config.OreColor.Value = OreColor[3]
		Config.OreTypes.Value = OreTypes[3]
		Ore.Color = Config.OreColor.Value
		print("It's a Bronze.")
	end
end

function _G.RockBreaking()
	
		
		Rocks.Parent = workspace
	Rocks.Position = Ore.Position
	local TP = TweenInfo.new(
		4,
		Enum.EasingStyle.Sine,
		Enum.EasingDirection.Out,
		0,
		false,
		0
	)

	local Goal = {
		Transparency = 1,
		
	}

	local augh = TWS:Create(Ore, TP, Goal)
	augh:Play()
	task.delay(4)
		Ore.Parent = nil
	
end

Randomization()
SettingUp()

idk but you can change this

local function SettingUp()
	local strToNum = {
		['Rock'] = 1,
		['Copper'] = 2,
		['Bronze'] = 3
	}
	local thing = Ore:GetAttribute("OreTypes")
	local n = strToNum[thing]

	Config.Cooldown.Value = Cooldowns[n]
	Config.DropMax.Value = DropMax[n]
	Config.DropMin.Value = DropMin[n]
	Config.HP.Value = HP[n]
	Config.OreColor.Value = OreColor[n]
	Config.OreTypes.Value = OreTypes[n]
	Ore.Color = Config.OreColor.Value

	print("It's a ", thing)
end

If you want to make your code even better,

	Config.Cooldown.Value, Config.DropMax.Value, Config.DropMin.Value, Config.HP.Value, Config.OreColor.Value, Config.OreTypes.Value, Ore.Color = Cooldowns[n], DropMax[n], DropMin[n], HP[n], OreColor[n], OreTypes[n], Config.OreColor.Value

takes up less lines gets the same thing achieved.

1 Like