I am trying to make an fps command

So I am making an admin script and I am trying to make an fps (frames per second) command so a player can view their current frame rate, the code was working up until now and it still updates every few milliseconds and changes colour based off the frame rate performance but when I type out the command again to turn it off, it says FPS is not a valid member of ScreenGui “FPSGui”

elseif msg:lower():sub(1,4) == freeCommandPrefix.."fps" then --FPS command (Frames Per Second)
					if plr.PlayerGui:FindFirstChild("FPSGui") == nil then
						local clonedUi = script.FPSGui:Clone()
						clonedUi.Parent = plr.PlayerGui
						while wait(0.1) do
							local fps = math.floor(game.Workspace:GetRealPhysicsFPS())
							clonedUi.FPS.Text = "FPS: "..fps
							if fps <= 35 then
								clonedUi.FPS.TextColor3 = Color3.fromRGB(255, 38, 19)
							elseif fps > 35 and fps <= 40 then
								clonedUi.FPS.TextColor3 = Color3.fromRGB(255, 255, 39)
							elseif fps > 40 and fps <= 60 then
								clonedUi.FPS.TextColor3 = Color3.fromRGB(57, 255, 47)
							elseif fps > 60 then
								clonedUi.FPS.TextColor3 = Color3.fromRGB(19, 255, 240)
							end
						end
					else
						plr.PlayerGui:FindFirstChild("FPSGui"):Destroy()
					end

I have tried using find first child for finding the FPS text label but it still says attempt to index nil with ‘Text’

Change to

					if plr.PlayerGui:FindFirstChild("FPSGui") == nil then
                        FPSShown = true
						local clonedUi = script.FPSGui:Clone()
						clonedUi.Parent = plr.PlayerGui
						while FPSShown do
							local fps = math.floor(game.Workspace:GetRealPhysicsFPS())
							clonedUi.FPS.Text = "FPS: "..fps
							if fps <= 35 then
								clonedUi.FPS.TextColor3 = Color3.fromRGB(255, 38, 19)
							elseif fps > 35 and fps <= 40 then
								clonedUi.FPS.TextColor3 = Color3.fromRGB(255, 255, 39)
							elseif fps > 40 and fps <= 60 then
								clonedUi.FPS.TextColor3 = Color3.fromRGB(57, 255, 47)
							elseif fps > 60 then
								clonedUi.FPS.TextColor3 = Color3.fromRGB(19, 255, 240)
							end
                            wait()
						end
					else
                        FPSShown = false
						plr.PlayerGui:FindFirstChild("FPSGui"):Destroy()
					end

Also insert local FPSShown = false to first line

It still says it cannot find the FPS text label of the screen Gui.

image

FPSGui:WaitForChild(“FPS”)
Maybe its not loaded?

Ok I will try now, the confusing thing is that it just stopped working without changing anything and I check the player’s guis and it is there :thinking:

Any other script Interfering with that GUI?

I will try searching now, I don’t believe so though.

I believe I have found the error, it is deleting it but there is no delay so it is cloning the gui again.

So, I guess something was interfering. I hope I could help you out.

1 Like

Hello again, I found out the error was that because my fps command is for an entire admin system, I have it set so the owner of the game is automatically given admin and I published the game only recently but I still had my user Id in the array of admins, I forgot to remove it so it was replicating the command and doing it twice.

1 Like