First of all, if you haven't touched scripting yet, I'd recommend checking out a beginner's guide: http://wiki.roblox.com/index.php?title=Intro_to_Scripting
Now, on to you're question:
So basically I am trying to make a script that dims PointLights in radius when a specific NPC in near it
Let's start with the "radius" part - Fortunately, Vector3 has a handy "magnitude" property built-in for you!
http://wiki.roblox.com/index.php?title=Magnitude
The distance between two parts can be calculated with the following piece of code: (part1.Position - part2.Position).magnitude
Given this, let's say that both your light and the NPC are in Workspace. The NPC is named "Noob", and the light is located at game:GetService("Workspace").Part.Light
Let's start making the script by setting some variables, shall we?
local ws = game:GetService("Workspace")
local part, npcTorso = ws.Part, ws.Noob:FindFirstChild("Torso")
local light = part:FindFirstChild("Light")
local maxBrightness = 2
local minBrightness = 0.1
local radius = 15
Now, let's check the distance between the NPC and the Light every 1/30 of a second. When the distance is checked, we'll adjust the light's brightness according to the distance.
while wait(1/30) do
local distance = (npcTorso.Position - part.Position).magnitude
if distance <= radius then
local brightness = (distance/radius) * maxBrightness
if (brightness < minBrightness) then
brightness = minBrightness
end
light.Brightness = brightness
end
end
Of course, you may want to adjust some of the variables.
1 comment
This wiki page will tell you how to get the distance between two parts; http://wiki.roblox.com/index.php?title=Magnitude