If the player dies while inside a lighting zone, it gets stuck on that lighting but doesn’t print any errors. Can anybody tell me whats wrong?
local Lighting = game:GetService("Lighting")
local TweenService = game:GetService("TweenService")
local lightingZones = workspace:WaitForChild("Locations")
local character = script.Parent
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
local updateTime = 0.25
local noZoneDefault, shiftTime = true, 2
local defaultSettings = {
Density = Lighting.Atmosphere.Density,
Color = Lighting.Atmosphere.Color,
Decay = Lighting.Atmosphere.Decay
}
local currentTween
local function setLightingProperties(newSettings)
if currentTween then currentTween:Pause() end
currentTween = TweenService:Create(
Lighting.Atmosphere,
TweenInfo.new(newSettings.ShiftTime or shiftTime, Enum.EasingStyle.Linear),
{ Density = newSettings.Density,
Color = newSettings.Color,
Decay = newSettings.Decay
}
)
currentTween:Play()
end
local overlapParams = OverlapParams.new()
overlapParams.FilterType = Enum.RaycastFilterType.Include
overlapParams.FilterDescendantsInstances = {lightingZones}
local currentZone
while true do
local lightingZone
for i, zone in pairs(workspace:GetPartsInPart(humanoidRootPart, overlapParams)) do
if lightingZone then
if zone:GetAttribute("Priority") > lightingZone:GetAttribute("Priority") then
lightingZone = zone
end
else
lightingZone = zone
end
end
if lightingZone then
if lightingZone ~= currentZone then
currentZone = lightingZone
setLightingProperties(lightingZone:GetAttributes())
end
else
if noZoneDefault == true and currentZone then
setLightingProperties(defaultSettings)
end
currentZone = nil
end
task.wait(updateTime)
end