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

How can I change the position of multiple objects with the same name?

I making a stage with lighting but I want to move the light beam to different angles. I'm doing it by moving the attachment to the location I want the light beam to face, but models have the same name. So how can I do it?

This script currently works for only one of the lights

local Epic = script.Parent.ClickDetector

function onClick() for i,v in pairs (game.Workspace.groundLights:GetChildren()) do if v.Name == "ParCan" then

workspace.groundLights.Head.B.Attachmentend.Position = Vector3.new(0,0,0)

	end
end

end Epic.MouseClick:connect(onClick)

1 comment

0

Attachments' possitions are relative to the part it is inside of. If you want it to go somewhere that isn't relative, you can use WorldPosition instead, I think..

1 answer

Prob something like this?


local Epic = script.Parent.ClickDetector

function onClick()
	for i,v in pairs (game.Workspace.groundLights:GetDescendants()) do
		if v.Name == "ParCan" then
			v.FindFirstChild:("Attachmentend").Position = Vector3.new(10,0,0)
		end
	end
end

Epic.MouseClick:connect(onClick)

tbh idk what ParCan is , u might need to remove the entire if v.Name == "ParCan" then

6 comments

0

I get this error: Expected ':' not '.' calling member function FindFirstChild

0

my bad i was typing this pretty fast and i made a mistake v.FindFirstChild:("Attachmentend").Position = Vector3.new(10,0,0)

0

Workspace.Part.Script:6: Expected identifier when parsing method name, got '('

0

Did you try without the if v.Name == "ParCan" then?

0

still gives same error, it doesn't like the ":" before ("Attachmentend")

0

v:FindFirstChild("Attachmentend").Position = Vector3.new(10,0,0) it should be like this

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