Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

[?] Server Calling "TextService" 'nil'

I'm currently making an overhead Gui that uses real-time onChanged PlayerData. It works 100% fine in studio solo, but when I enter the game, it gives me this error:

http://bit.ly/2pWaO4Q

ServerScriptService.TitleDisplay:18: attempt to index upvalue 'TextService' (a nil value)

I am using game:GetService("TextService") to call it, but it breaks still.

Code that uses TextService:

local TextService = game:GetService("TextService")

game.Players.PlayerAdded:connect(function(player)
repeat wait() until player.Character
	local char = player.Character
	getRole(player)
	player.Changed:connect(function()
		repeat wait() until player.Character
			wait()
			getRole(player)
	end)
end)

function GetStringTextBounds(text, font, textSize, sizeBounds)
	sizeBounds = sizeBounds or Vector2.new(10000, 10000)
	return TextService:GetTextSize(text, textSize, font, sizeBounds)
end

function GetNumberOfSpaces(str, font, textSize)
	local strSize = GetStringTextBounds(str, font, textSize)
	local singleSpaceSize = GetStringTextBounds(" ", font, textSize)
	return math.ceil(strSize.X / singleSpaceSize.X)
end

...

		local numNeededSpacesName = GetNumberOfSpaces(formatPrefix, useFont, useTextSize)
		local numNeededSpacesPrefix = GetNumberOfSpaces(formatName, useFont, useTextSize)
		local gui = script.PlayerOverhead
		local clone = gui:Clone()
		local PrefixLabel = clone.PName.PrefixLabel
		local NameLabel = clone.PName.NameLabel
		local TitleLabel = clone.Title.TitleLabel
		clone.Parent = p.Character.Head
		PrefixLabel.Text = usePrefix .. string.rep(" ", numNeededSpacesPrefix)
		PrefixLabel.PrefixLabelShadow.Text = usePrefix .. string.rep(" ", numNeededSpacesPrefix)
		PrefixLabel.TextColor3 = Prefix.PrefixColor.Value
		NameLabel.Text = string.rep(" ", numNeededSpacesName) .. "[" .. useName .. "]"
		NameLabel.NameLabelShadow.Text = string.rep(" ", numNeededSpacesName) .. "[" .. useName .. "]"

5 comments

0

We can't help if you don't include your code.

0

Where is line 18 on this?

0

That's the thing. What I gave you WAS line 18. I copied+pasted the exact script.

0

My guess though was that it meant this part: "return TextService:GetTextSize(text, textSize, font, sizeBounds)" since when I changed the script up (trying to debug--still no help) it always pointed to that with the same error.

0

I've tried many debugging tricks like moving code around, making the functions just 1 function, or even turning the part of the script into a separate module, and nothing works. I either get that error, or "unable to cast double to token" error.

1 answer

I decided not to use this method, since it must be a Core-only method or I am just using it wrong.

An alternative for this (in the future) can be to just use string.len instead of what I am doing.

This discussion is preserved as it was. New answers, comments, and votes are closed.