Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How can I select different part names within a function?

function generateMedKit(name,XYZ) 
	local MedKits = game.ServerStorage.MedKits.name  
		MedKits.Position = XYZ                       
		MedKits.Parent = game.Workspace             
	end                                             
generateMedKit("Med1","Vector3.new(463.39, 28.452, 220.52)")
generateMedKit("Med2","Vector3.new(463.39, 28.452, 208.84)")
generateMedKit("Med3","Vector3.new(463.39, 28.452, 196.33)")

I understand what is not working here, but I am not sure how to fix it. The variable is being set to "game.ServerStorage.MedKits.name", but I need the script to make "name" whatever I write within the argument like "Med1" that way for each function I call I can select a different part within the ServerStorage.

function generateMedKit(name,XYZ) 
	local partName = name
	local MedKits = game.ServerStorage.MedKits.partName
		MedKits.Position = XYZ                       
		MedKits.Parent = game.Workspace             
	end                                             
generateMedKit("Med1","Vector3.new(463.39, 28.452, 220.52)")
generateMedKit("Med2","Vector3.new(463.39, 28.452, 208.84)")
generateMedKit("Med3","Vector3.new(463.39, 28.452, 196.33)")

I also tried doing it this way trying make "partName" a variable of the "name" I wanted, but it didn't work.

Sorry if it is hard to understand what I'm asking, I just started scripting and can't explain this stuff well yet. I'm not even sure if any of this script could even work.

4 comments

1

Edit the post so the code is within a code block

0

you want it to find the medkit with the specific name?

0

or generate a medkit with the name?

0

I have a group called MedKits with Med1 through Med3 within it and I need to select one Med at a time. So yes I am trying to select a specific Med

1 answer

✓ Accepted answer

Use :FindFirstChild(name)

function generateMedKit(name, XYZ) 
    local MedKits = game.ServerStorage.MedKits:FindFirstChild(name)
	MedKits.Position = XYZ                       
        MedKits.Parent = game.Workspace             
    end                                             
generateMedKit("Med1","Vector3.new(463.39, 28.452, 220.52)")
generateMedKit("Med2","Vector3.new(463.39, 28.452, 208.84)")
generateMedKit("Med3","Vector3.new(463.39, 28.452, 196.33)")

Accept the answer if it helped you!

This discussion is preserved as it was. New answers, comments, and votes are closed.