Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

[?] Server Calling "TextService" 'nil'

Asked by 7 years ago
Edited 7 years ago

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 .. "]"
0
We can't help if you don't include your code. BlueTaslem 18071 — 7y
0
Where is line 18 on this? User#15029 30 — 7y
0
That's the thing. What I gave you WAS line 18. I copied+pasted the exact script. nforeman 15 — 7y
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. nforeman 15 — 7y
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. nforeman 15 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago

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.

Ad

Answer this question