I am trying to get the part of the tool instead of the name with this code/
How can i change “Handle” the name to find the part instead? while keeping the available tools.
What exactly do you mean when you say find the part instead of the name? Aren’t you already doing that?
FindFirstChild returns the first object to have the same name as what you pass in, or nil if none of the children (descendants if recursive is true) have the name specified.
When using "..", this combines (or concatenates) two strings into one string, example:
print("He" .. "llo") --> Hello
Also, side pointer, if the weapon doesn’t exist for some reason this code will error. If you expect it to always exist, use WaitForChild instead of FindFirstChild.
Or - if it sometimes may not be there, you should do the following:
local Weapon = game.ReplicatedStorage:WaitForChild("ToolModels"):FindFirstChild(availableTools[i][1])
if Weapon then
-- code here
Weapon.Handle.BrickColor = BrickColor.Random() -- example
else
print("Weapon didn't exist!")
end
If you need anything explained further let me know and I’ll do my best to help you out!
I would suggest searching up some Roblox Lua tutorials as you do not seem to understand the basics of objects/variables.
When you use FindFirstChild or reference a part by using a Variable that variable becomes a direct reference to the part meaning you can then use that variable to edit the part.
Example:
local Part = workspace:FindFirstChild("Ball")
Part.BrickColor = BrickColor.red()
Though this is a simple example it means the “Part” variable is now a direct reference to the “Ball” object in workspace.
I know i make no sense but what i want is to find the part of all the items in my folder instead of its name.
This code finds the folder called toolmodels and availbetools is getting all the tools, the “Handle” gets all the tools that has the name Handle in them ex(“GunHandle”, ShotgunHandle"), i want to get the tools from their ClassName like Part or MeshPart. But Changing Handle to Part does not work because Part is not a name.
It works but i need theavaiableTools[i][1] to be in there because if i do this, even tho the statement is true it will change every item so i need the avaibletools to make it sepearte for each tools. Like i want one item to be bought with cash and another with coins.