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

How can I change the properties of multiple parts?

Asked by 8 years ago
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.

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. Thundermaker300 554 — 8y

1 answer

Log in to vote
0
Answered by
Sir_Melio 221 Moderation Voter
8 years ago
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)

Ad

Answer this question