My FPS goes Lower and lower for no reason

Hello
I need Help with my sun Script or my Plugins is the Problem IDK

The Problem my FPS goes lower and lower

there’s no error’s
I used the Celestial Body Dragger Plugin that move’s the sun were I want

if this Help’s

Here’s the Script

local sunDirection = game.Lighting:GetSunDirection()

local sun_Detect = 10000
local coolDown = 0
local coolDownDuration = 1

local Safe = true
local Burning = false

local function BurnPlayer()
    character.Humanoid:TakeDamage(5)
    Burning = false
    coolDown = coolDownDuration
end

local function SetSafe()
    if Burning then
        Burning = false
    end
end

game:GetService("RunService"):BindToRenderStep("SunService", Enum.RenderPriority.Camera.Value + 1, function(deltaTime)
    local ray = Ray.new(character.HumanoidRootPart.Position, sunDirection * sun_Detect)
    local PartFound = workspace:FindPartOnRay(ray, character)

    if PartFound then
        Safe = true
        print("you're good")
        SetSafe()
    else
        Safe = false
        coolDown = math.max(0, coolDown - deltaTime)
        if coolDown <= 0 then
            if not Burning then
                Burning = true
                BurnPlayer()
            end
        end
        print("Find Player")
    end
end)

game.Lighting:GetPropertyChangedSignal("TimeOfDay"):Connect(function()
    sunDirection = game.Lighting:GetSunDirection()
end)

Its because printing to the console every frame, especially with messages like “you’re good” or “Find Player,” can degrade performance over time. Try to minimize or remove these print() statements..

Comment out “Find Player” and “you’re good”.

1 Like

This is prolly because your creating a new recast basically every frame in render stepped.

I don’t use Roblox studio anymore but if there is a way to create rays less often use that.