So i want to make a math random that dosent repeat any time, i want that a folder have the max space of 4 items but i want that the tools is fill up the folder randomly. i have 4 items and i what i said is like when the script run he chose random numer of 1 to 4 and put in the folder and make sure that dont put the same number. So when the items can go randomly putted in the folder, like: First to go to folder is 3 after 1 after 4 after 2. This was just a example of how the script need to work
I know that my script will not work because i even finish but its working.
I aldery search for some codes reviews but i dont find nothing that truely help
math.randomseed(time() * tick())
local choosen_tool = tools[math.random(1, #tools)]
local atrib = choosen_tool:GetAttribute("class")
print(atrib)
for i=1, #pc do
if pc[i]:GetAttribute("class") == atrib then
math.randomseed(time() * tick())
local choosen_tool = tools[math.random(1, #tools)]
end
end
Btw all tools that is in variable tool have the number atribbute called class
ones of the issues that is pretty strange is the one that. everytime i test it chose number 4.
math.randomseed(time() * tick())
local rand = Random.new(100)
for i = 1, #tools, 1 do
local choosen_tool = rand:NextInteger(1, #pc:GetChildren())
end
local clone = choosen_tool:Clone()
its having problem at choosen_tool for variable clone bec yes
local pc = workspace.Carnes.Picanhas:GetChildren()
math.randomseed(time() * tick())
local choosen_tool
local rand = Random.new(100)
print("Step1")
for i = 1, #tools, 1 do
choosen_tool = tools[rand:NextInteger(1, #pc)]
end
print("Step2")
local clone = choosen_tool:Clone()
so i tried the script but nothing work so i put the prints and i see that wont go to step 2, btw i remove #pc:GetChildren() because the variable aldery is a get children
Do you see any errors in the output? Also, does workspace.Carnes.Picanhas have any objects inside of it? If it doesn’t, Random:NextInteger() will fail.
No workspace.Carnes.Picanhas when the script is not run dont have nothing in it. im trying to make that if have somenthing in it the mathrandom dont get the same item that aldery have in folder Picanhas
yeah i think about that but i cant do that because the script can run multiply times if i touch the part and but now i have a idea maybe when the script finish and the item work is aldery finish i can just put the item back to the tools.
local folder = game.ServerStorage:WaitForChild("Carninhas"):WaitForChild("Picainhas")
local tools = folder:GetChildren()
local pc = workspace.Carnes.Picanhas:GetChildren()
math.randomseed(time() * tick())
local choosen_tool
local rand = Random.new(100)
local chosen = rand:NextInteger(1, #tools)
choosen_tool = tools[chosen]
table.remove(tools, chosen)
print("Step2")
local clone = choosen_tool:Clone()
Ok soo i think its was supose to work but now when i run the script the script just get the number 4, i run 4 times and always was number 4 idk what happend i think can bet random variable problem
Acho que seria uma melhor ideia se você colocasse um task.wait() dentro do for loop. Isso vai dar tempo para que o gerador de número pseudo-aleatório possa calcular um resultado diferente.