For context: I’m trying to make a game/script where the player can change their fps.
The error is in the title–attempt to preform arithmetic (div) on number and nil.
This is my code:
local gui = script.Parent
local textBox = gui.Frame.TextBox
local fps = tonumber(textBox.Text)
local clock = tick()
while true do
if fps == nil then
fps = 60
else
fps = tonumber(textBox.Text)
end
while clock + 1/fps > tick() do end
wait()
clock = tick()
end
It’s saying that it can’t do division on a number and nil, but it should be turning whatever the player types into the TextBox into a number with tonumber()
. And if it’s empty then the default should be 60 fps.
The error runs first thing, before I type anything into the TextBox. And when I do type nothing happens.
I want to know what I’m doing wrong and how this can be fixed.