How would i randomize it

I’m extremely tired at the moment of writing this and i cannot think of a way to make the loot pool randomized every time you open a stash.

The script is messy but i will clean it up soon.

local cl = game.ReplicatedStorage.INVENremotes.Close

Debris = game:GetService("Debris")
local Global = require( game:GetService("ReplicatedStorage").kInteracts_ReplicatedStorage.Global )
local Attachment = script.Parent.Example

local InteractionPoint = Global:InitializeInteractObject(Attachment)

InteractionPoint.Interacted:Connect(function(plr)
	local g = plr.PlayerGui.LootInventory
	local l = g.MainLoot.LootLayout
	local c = script.Parent.LootSettings.Contents
	local ls = script.Parent.LootSettings
	cl:FireClient(plr)
	print("Universal", ls.LootType.Universal.Value)
	print("Stash",ls.LootType.Stash.Value)
	print("Millitary",ls.LootType.Millitary.Value)
	print("Scrap",ls.LootType.Scrap.Value)
	if ls.LootType.Universal.Value == true then --UNIVERSAL
		for _, Child in pairs(script.Parent.LootSettings.Contents:GetChildren()) do
			if Child:IsA("BoolValue")then
				if Child.Name == "Watch" then
					l.Watch.Visible = true
				elseif Child.Name == "Flash" then
					l.Flash.Visible = true
				elseif Child.Name == "Screwdriver" then
					l.Screwdriver.Visible = true
				elseif Child.Name == "Grenade" then
					l.Grenade.Visible = true
				elseif ls.LootType.Stash.Value == true then --STASH
					if Child.Name == "Watch" and Child.Value == true then
						l.Watch.Visible = true
					elseif Child.Name == "Flash" and Child.Value == true then
						l.Flash.Visible = true
					elseif ls.LootType.Scrap.Value == true then --Scrap
						if Child.Name == "Watch" and Child.Value == true then
							l.Watch.Visible = true
						elseif Child.Name == "Screwdriver" and Child.Value == true then
							l.Screwdriver.Visible = true
						end
					end
				end
			end
		end
	end
end)

image

have you heard of math.random? its pretty cool.

code sample:

local randomness = math.random(1,4)
if randomness == 1 then
print("1 has been chosen!")
end
if randomness == 2 then
print("2 has been chosen!")
end
if randomness == 3 then
print("3 has been chosen!")
end
if randomness == 4 then
print("4 has been chosen!")
end

I do have a math.random inside of a few bool values that determine if it should spawn or not.

	local num = {1, 2}
	local c = num[math.random(#num)] 
	print(c)
	if c == 1 then
		script.Parent.Value = true
	elseif c == 2 then
		script.Parent.Value = false
	end
end

The bool values are inside of the “Contents” Folder
image

But i am currently fully redoing everything because the way i scripted it was really bad.

Another way of selecting randomly loot that is easier to make changes to:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.