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:
- A Button in a GUI has been clicked.
- The Player is less than 50 studs away from another object, in this case being rightlightpos.

1 comment
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.