example , part1 has a script but part2 doesnt , how to put a script with a code on part2 using part1's script ? . exapmle , the code I want to put on part2's script is
Print("Hello")
example , part1 has a script but part2 doesnt , how to put a script with a code on part2 using part1's script ? . exapmle , the code I want to put on part2's script is
Print("Hello")
Use ModuleScripts to be able to use the same functions in multiple different scripts. Here's a link on how to use ModuleScripts: https://devforum.roblox.com/t/how-do-i-use-modulescripts/237334
You can also just use 1 main script, and then place the parts you want to apply code to in 1 folder inside Workspace. Then you can loop through each of the part in the folder like so:
local PartsFolder = workspace.PartsFolder
for key, value in pairs(PartsFolder:GetChildren()) do
print(value.Name) -- prints the name of the part
end
PartsFolder:GetChildren() returns a list of the folder's children, which would be the parts you put in it. Lists in Lua are called tables so I will refer to them as tables from now. What the for loop does is it it goes through the parts inside the table one by one.
key indicates the order the part is in inside the table, and value is the part itself.
We can rename key and value to more suitable names:
local PartsFolder = workspace.PartsFolder
for _, part in pairs(PartsFolder:GetChildren()) do
print(part.Name) -- prints the name of the part
end
key has been renamed to _ as variables that aren't used are usually named _. value has been renamed to part as that variable is the part object.
This discussion is preserved as it was. New answers, comments, and votes are closed.