Hello, i want to make pointlight shadows disappear when i walk away from them, i have a working script, but a problem here that i will need copy this script for every pointlight i will make, would be too large script, so, i want to make a script that will get every point light in workspace and when i walk away from it it will disappear.
I already tried few ways, but i didn’t work for me, because me and scripting is diffrent things, can you help me out?
while wait() do
local magnitude = (game.Players.LocalPlayer.Character.HumanoidRootPart.Position - workspace.Part.Position).Magnitude
if magnitude > 20 then workspace.Part.PointLight.Shadows = false
else workspace.Part.PointLight.Shadows = true
end
end
as you can see here it will make pointlight shadows dissapear, but only in one part, when i duplicate part, same name, same everything, it doesn’t work
We’ll make a loop for every point light in the workspace then basically just do what you were doing before on every light :
for _, light in pairs(game.Workspace:GetDescendants()) do
if not light:IsA("PointLight") then continue end
local magnitude = (game.Players.LocalPlayer.Character.HumanoidRootPart.Position - light.Parent.Position).Magnitude
if magnitude > 20 then light.Shadows = false
else light.Shadows = true end
end
Oh my bad you need to wrap this in a loop then it should work
game.RunService.RenderStepped:Connect(function()
for _, light in pairs(game.Workspace:GetDescendants()) do
if not light:IsA("PointLight") then continue end
local magnitude = (game.Players.LocalPlayer.Character.HumanoidRootPart.Position - light.Parent.Position).Magnitude
if magnitude > 20 then light.Shadows = false
else light.Shadows = true end
end
end)
game:GetService("RunService").RenderStepped:Connect(function()
for _, light in pairs(game.Workspace:GetDescendants()) do
if not light:IsA("PointLight") then continue end
local magnitude = (game.Players.LocalPlayer.Character.HumanoidRootPart.Position - light.Parent.Position).Magnitude
if magnitude > 20 then light.Shadows = false
else light.Shadows = true end
end
end)
The reason the first version didn’t work was because it only checked one time and when you got close it never updated again! Glad it works now make sure to mark solution!
Oh, and also, i’m trying to make it work for surfacelight too, but it doesn’t
game:GetService("RunService").RenderStepped:Connect(function()
for _, light in pairs(game.Workspace:GetDescendants()) do
if not light:IsA("PointLight") or light:IsA("SurfaceLight") then continue end
local magnitude = (game.Players.LocalPlayer.Character.HumanoidRootPart.Position - light.Parent.Position).Magnitude
if magnitude > 20 then light.Shadows = false
else light.Shadows = true end
end
end)
You have to add a not before the (it should also be and not or btw)
So like this:
game:GetService("RunService").RenderStepped:Connect(function()
for _, light in pairs(game.Workspace:GetDescendants()) do
if not light:IsA("PointLight") and not light:IsA("SurfaceLight") then continue end
local magnitude = (game.Players.LocalPlayer.Character.HumanoidRootPart.Position - light.Parent.Position).Magnitude
if magnitude > 20 then light.Shadows = false
else light.Shadows = true end
end
end)