Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to make each part seperate names??

Asked by
Nyxan 5
9 years ago

ok heres what i want the script to do i want it to go threw the model i set it to and change each parts name basically i want each part to have a different name 1-100

--[script]--
wait(4)
a = 0
part = game.Workspace.test:GetChildren()


for i = 1,100 do
    wait()  
    a = a + 1
    local rp = part[math.random(1,#part)]
b = game.Workspace.test:FindFirstChild(rp.Name)
if rp.Name == b then

else
    rp.Name = a
end 



end
0
Please put your code in a code block. Click the Lua button and put your code between the lines YellowoTide 1992 — 9y
0
First of all, edit your question, click the little blue Lua button, and put your code between the lines. funyun 958 — 9y

1 answer

Log in to vote
0
Answered by 9 years ago

Hello, your title is a bit misleading... but I think I understand what your asking. If not, then just let me know and I can answer it more accurately (:

I am not sure if this website allows us to just GIVE the answer away, So I will put comments indicating what some of the lines do.

Coding :

local contains = function(tab, mat) --takes in a table and to be matched value
for i, v in pairs(tab)do
if(v == mat)then
return true
end
end
return false
end

local randomize = function(model) --takes in path to model

local children = model:GetChildren()
local amount = #children

local used = {}

for i=1, amount do
local index = math.random(1, amount)
repeat index = math.random(1, amount) until not contains(used, index)
children[index].Name = i -- or children[i].Name = index
end

end

....After coding all of that I just realized something ...

I could have just did :

local function func() --[[code]] end

qq oh well, PM me if you need additional help (:

Ad

Answer this question