LocalScript:14: attempt to concatenate string with nil

Well my problem with the following localscript. is that to activate it needs a Value to be named EnabledPing, it works and everything, then I change the name of the value and it stops executing, all good until I change the name of the Value to EnabledPing and it stops working.

local TextPing = script.Parent
local ValueEnabled = game.Players.LocalPlayer:WaitForChild("JuegoConfg"):WaitForChild("Ping")

function GetPing()
	if ValueEnabled.Value == "EnabledPing" then
		local Ping = 300-((1/wait())*10)
		if Ping < 1 then
		end
		return math.floor(Ping)
	end
end
while wait (0.1) do
	if TextPing.Text ~= nil then
		TextPing.Text = "Ping: "..GetPing()
	end
end

print GetPing() to see if its returning a nil value. there must be something wrong with your function.

Two notable things:
Always make sure the function returns at least something
Parse numbers into a string before concatenating it

local TextPing = script.Parent
local ValueEnabled = game.Players.LocalPlayer:WaitForChild("JuegoConfg"):WaitForChild("Ping")

function GetPing()
	if ValueEnabled.Value == "EnabledPing" then
		local Ping = 300-((1/wait())*10)
		if Ping < 1 then
		end
		return math.floor(Ping)
	end
    return 0 -- default return value
end
while wait (0.1) do
	if TextPing.Text ~= nil then
		TextPing.Text = "Ping: "..tostring(GetPing())
	end
end
1 Like

The error is given to me on line 14, I tried to put if TextPing.Text ~= nil then on it but it doesn’t work.