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

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

Asked by 3 years ago

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)

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.. RAFA1608 543 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

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

0
I get this error: Expected ':' not '.' calling member function FindFirstChild SMHerobrine 2 — 3y
0
my bad i was typing this pretty fast and i made a mistake v.FindFirstChild:("Attachmentend").Position = Vector3.new(10,0,0) ezkatka1 50 — 3y
0
Workspace.Part.Script:6: Expected identifier when parsing method name, got '(' SMHerobrine 2 — 3y
0
Did you try without the if v.Name == "ParCan" then? ezkatka1 50 — 3y
View all comments (2 more)
0
still gives same error, it doesn't like the ":" before ("Attachmentend") SMHerobrine 2 — 3y
0
v:FindFirstChild("Attachmentend").Position = Vector3.new(10,0,0) it should be like this ezkatka1 50 — 3y
Ad

Answer this question