I’m trying to increase a density when player is getting closer using position, it works but is there a better approach?
local IsTouching = false
task.spawn(function()
for _,v in Character:GetChildren() do
v.Touched:Connect(function(Hit)
if tostring(Hit):lower():match("triggerfog") then
IsTouching = true
end
end)
v.TouchEnded:Connect(function(Hit)
if tostring(Hit):lower():match("triggerfog") then
IsTouching = false
end
end)
while true do
task.wait()
if IsTouching then
TweenService:Create(game:GetService("Lighting").Atmosphere, TweenInfo.new(0.2), {Density = math.abs((Character.PrimaryPart.Position - workspace.Folder.Union.Position).Magnitude) / 40}):Play()
end
end
end
end)
Highlighted parts are what’s suppose to increase the density.
(Middle is just what sets the boolean, like the player is inside an area)