Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can I get a Script to completely start over?

Asked by 1 year ago
Edited 1 year ago

I have made a FPS limiter script, and it's working just fine. But if the user changes the FPS limit to something else, they would need to rejoin the game for the changes to take effect, because the script wouldn't register the changes.

I have tried disabling and enabling again and cloning but none worked. Can someone help me out?

Script: (without the resetting code)

local FPSCAP = game.StarterGui.ScreenGui.System.FPS.LimitFPSto.Value 
local LOOPCount = 200 
local MLoopCount = 27 

local FPS = 0
local Broken = 0
local function DOLOOP()
    spawn(function()
        while true do
            game:GetService("RunService").Heartbeat:Wait()
            if FPS+5 < FPSCAP and Broken <= LOOPCount*MLoopCount then
                Broken += 1
                break
            end
        end
    end)
end

game:GetService("RunService").RenderStepped:Connect(function(delta)
    FPS = 1/delta
end)

spawn(function()
    while true do
        game:GetService("RunService").Heartbeat:Wait()
        if FPS >= FPSCAP then
            spawn(function()
                for i = 1, LOOPCount do
                    DOLOOP()
                end
            end)
        end
    end
end)
spawn(function()
    while wait(1) do
        Broken = 0
    end
end)

2 answers

Log in to vote
0
Answered by 1 year ago

This might be a bad take because I'm still fairly new to programming, but try using > BindableEvents with two scripts, one that fires an event when a change is made, and one script that actually handles the changes. This should remove the restart script thing entirely and it will make the code more efficient as well. Hope this helps:)

0
I don't understand anything about it. I belive it won't helpw ith the issue because once the script is started, the local FPS cap value won't change anymore, and it'll just be what the value was at joining TheEggGamerRobloxYT 0 — 1y
Ad
Log in to vote
0
Answered by 1 year ago

I’m gonna need to see your script to help ya here.

0
Why did you post this as an answer? You can make a comment under his question. xInfinityBear 1777 — 1y
0
I edited the original post, check it there TheEggGamerRobloxYT 0 — 1y

Answer this question