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 .. "]"
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.