I have a teleport script that I want to only teleport into unlit areas. I have a working script, but I'm afraid that if I add too many lights it will lag.
script.Parent.Activated:Connect(function()--the relevant function
local mouse = player:GetMouse()
local hit = mouse.Hit
local h = hit.p
local a = true
if mouse.Target and b == true then
for _, part in pairs(game.Workspace.Lights:GetChildren()) do
local m = (mouse.Target.Position - part.Position).magnitude
if m <= part.PointLight.Range then
a = false
end
end
if a == true then
fadeout()
player.Character:MoveTo(h)
fadein()
else
local gui = game:GetService("ReplicatedStorage").Gui.Warning:Clone()
gui.Parent = player.PlayerGui
end
b = false
wait(.75)
b = true
end
end)
Is there a way to see if the place I'm teleporting to is lit without going through each light in the folder?
