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 change the properties of multiple parts?

function whenClicked()
	local plr = game.Players.LocalPlayer
	local playerpos = plr.Character.Torso.Position
	local rightlightpos = game.Workspace.FlashLight2.Union.Position
	local difference = playerpos - rightlightpos
	local number = 50
	if difference.magnitude < number then
		local xa = game.Workspace.Lobbthing.Part
		xa.BrickColor = BrickColor.new("Black")
		
	
	end
end

script.Parent.MouseButton1Down:connect(whenClicked)

The purpose of this script is to change the color value of a part within a model called "Lobbthing", once a player is a certain distance away from another object. However, my goal is to make this script work for all of the objects in the model called "Part" and that does not happen. I know that there is a way to do this but at my current stage within this language I am unable to do that. Note: This script activates when two conditions are met:

  1. A Button in a GUI has been clicked.
  2. The Player is less than 50 studs away from another object, in this case being rightlightpos.

1 comment

0

Is that in a script or Localscript? If it's in a script it will not work because you cannot call LocalPlayer inside a script.

1 answer

✓ Accepted answer
function whenClicked()
    local plr = game.Players.LocalPlayer
    local playerpos = plr.Character.Torso.Position
    local rightlightpos = game.Workspace.FlashLight2.Union.Position
    local difference = playerpos - rightlightpos
    local number = 50
    if difference.magnitude < number then
        for i,v in pairs(game.Workspace.Lobbthing:GetChildren()) do
            if v.Name == "Part" then
                v.BrickColor = BrickColor.Black()
            end
        end
    end
end

script.Parent.MouseButton1Down:connect(whenClicked)

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