while task.wait() do
if (t.Position-p.Position).Magnitude < 10 then
p.Color = Color3.new(0,1,0)
elseif (t.Position-p.Position).Magnitude < 5 then
p.Color = Color3.new(1,1,0)
end
end
and i have another part with the same script, it will conflict with each other, how do i make it not conflict?
so if one part is changing “p” to green, but the other one (which is closer, see script) is trying to change it to yellow, it conflicts and the colors switch back and forth
If the “p” is changing to green, you should probably go see a doctor.
On a more serious note though, you can just check if the color is already yellow and not change it back.
local one : BasePart = -- [[your part t here]]
local two : BasePart = -- [[your part p here]]
local GREEN = Color3.new(0,1,0)
local YELLOW = Color3.new(1,1,0)
while task.wait() do
local distance = (one.Position-two.Position).Magnitude
if distance < 10 and two.Color ~= YELLOW then
two.Color = GREEN
elseif distance < 5 then
two.Color = YELLOW
end
end
If you wanna expand on this and add more colors though, I would recommend making a single script for both. That makes it a lot easier to work with multiple parts setting things. You could just calculate the max distance and set the color accordingly.
sorry for replying so late, i was able to fix it by setting a value with numbers based on distance and checking if it was equal to a certain value
like this:
if mag <= 10 and z.Value == 0 then
--blah blah
z.Value == 1
elseif mag <= 5 and z.Value == 1 then
-- blah blah
z.Value == 2
end