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:
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
We can't help if you don't include your code.
Where is line 18 on this?
That's the thing. What I gave you WAS line 18. I copied+pasted the exact script.
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.
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.