Attempt to perform arithmetic (div) on nil and number

Hi!
My frist post here in a while lol
So, I decided to make my FPS Counter RGB (The FPS/100), because it would look cool.
But, I don’t use math very much in my code, os I aleays have errors with it when I need it.
I know my RGB Script works, but the math doesn’t.

task.wait(5)
local attrib = script.Parent:GetAttribute("FPS")
local Speed = attrib/100
while true do
	Speed = attrib/100
	for Transition = 0, 1, 0.001 * Speed do
		script.Parent.TextColor3 = Color3.fromHSV(Transition, 1, 1)
		task.wait()
	end
end

Thanks!

1 Like

Are you sure the Attribute FPS isn’t nil?

1 Like

It isn’t, I added the task.wait at the stat to give it time to load. Here’s the FPS script.

local FPS = 0

local Tiempo = tick()

local att = script.Parent.Parent.PC.FPS:GetAttribute("FPS")

spawn(function()
	while game:GetService("RunService").RenderStepped:wait() do
		local Transcurrido = math.abs(Tiempo-tick())
		Tiempo = tick()
		FPS = math.floor(1/Transcurrido)
		script.Parent.Parent.PC.FPS:SetAttribute("FPS",FPS)
	end
end)

game:GetService("RunService").Stepped:Connect(function()
	script.Parent.Text = tostring(FPS) .. " fps"
end)
1 Like

Are both of these scripts client sided?

Yes. It loads on the server but goes right into the PlayerGui
image

1 Like

Try printing the attrib in that script

image

Nothing

1 Like

Did you print it above this? If yes, then it is nil or it doesn’t exist at all.

No

task.wait(5)
local attrib = script.Parent:GetAttribute("FPS")
local Speed = attrib/100
while true do
	print(attrib)
	print(Speed)
	Speed = attrib/100
	for Transition = 0, 1, 0.001 * Speed do
		script.Parent.TextColor3 = Color3.fromHSV(Transition, 1, 1)
		task.wait()
	end
end
1 Like

Well it can’t even get to it because the first

is causing the error.

Likely doesn’t exist, make sure you have created the attribute on the object.

Yes, how would I do the division? I dont see the print when I changed attrib to outside the loop. I’m creating the attribute right now bc idk if the script is creating it.

1 Like

Try creating the attribute on client, inside LocalScript instead of server side Script

shoot i crashed it brb

1 Like

image

yeah i did something wrong with the loop, addign a task.wait()

1 Like

Yeah, infinite loops always need to have some kind of delay between each loop, otherwise they will exhaust execution time.

1 Like


It prints 0 and stops.

1 Like

Yeah because the print isn’t in loop, but if it prints 0 idk whats wrong. try doing

local Speed = tonumber(attrib)/100


I dont know if it’s getting to the loop even.

task.wait(5)
local attrib = script.Parent:GetAttribute("FPS")
local Speed = tonumber(attrib)/100
local PrintDebugInfo = true --/////not reccomended, floods the console
print(attrib)
while true do
	Speed = tonumber(attrib)/100
	task.wait()
	for Transition = 0, 1, 0.001 * Speed do
		script.Parent.TextColor3 = Color3.fromHSV(Transition, 1, 1)
		if PrintDebugInfo then print(attrib) end
		task.wait()
	end
end
1 Like

Could you send me the .rbx file with the extracted system? So I could have a look at it.