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

[SOLVED] How do I solve this problem with TextBounds?

Asked by 9 years ago

So, I'm making a custom chat, but instead of making it simple I want to have the player's name a different color/font to the rest of the message. This somehow works perfectly in studio but does not work properly in online mode as seen in this place. How do I fix this problem, here's my function which returns no errors, works perfectly in studio but not in online mode:

function addMessage(speaker,msg,chat,color)
    for i,v in pairs(chat:GetChildren()) do
        if v:IsA("Frame") and string.sub(v.Name,1,7) then
            v.ActualPosition.Value = v.ActualPosition.Value-32
            v:TweenPosition(UDim2.new(0,5,0,v.ActualPosition.Value),"Out","Sine",0.5,true)
            v.Name = "Message"..tostring(tonumber(string.sub(v.Name,8))+1)
            if v.Name == "Message6" then
                v:TweenPosition(UDim2.new(0,5,0,-62),"Out","Sine",0.5,true)
                game:GetService("Debris"):AddItem(v,0.5)
            end
        end
    end
    local ChatFrame = Instance.new("Frame",chat)
    ChatFrame.Name = "Message1"
    ChatFrame.BackgroundTransparency = 1
    ChatFrame.Position = UDim2.new(0,5,0,149)
    ChatFrame.Size = UDim2.new(0,0,0,32)
    local ActualPosition = Instance.new("IntValue",ChatFrame)
    ActualPosition.Name = "ActualPosition"
    ActualPosition.Value = 149
    local Name = Instance.new("TextLabel",ChatFrame)
    Name.Name = "Name"
    Name.BackgroundTransparency = 1
    Name.TextColor3 = color
    Name.TextStrokeTransparency = 0.5
    Name.Font = "SourceSans"
    Name.FontSize = "Size18"
    Name.Text = speaker
    Name.Size = UDim2.new(0,Name.TextBounds.X,0,Name.TextBounds.Y)
    Name.ZIndex = 2
    local Message = Instance.new("TextLabel",ChatFrame)
    Message.Name = "Message"
    Message.BackgroundTransparency = 1
    Message.TextColor3 = Color3.new(255,255,255)
    Message.Font = "SourceSansLight"
    Message.FontSize = "Size18"
    Message.TextXAlignment = "Left"
    Message.TextYAlignment = "Top"
    Message.TextWrapped = true
    Message.Text = msg
    Message.Size = UDim2.new(0,350,0,36)
    Message.Position = UDim2.new(0,Name.TextBounds.X+2,0,0)
    Message.ZIndex = 2
    local Shadow = Message:Clone()
    Shadow.Parent = Message
    Shadow.TextColor3 = Color3.new(0,0,0)
    Shadow.Position = UDim2.new(0,-1,0,1)
    Shadow.ZIndex = 1
end

If you really want to see the rest of the script go here, although I don't see any reason why the rest of it would affect it. THIS IS IN A SERVER SCRIPT!

0
2 Up votes. This Question should be answered. I'll up vote the right answer as well. Vezious 310 — 9y
1
Tsk, tsk. I remember when as soon as you posted a script with more than 30 lines, everyone hated you. This is unfair. EzraNehemiah_TF2 3552 — 9y
0
Is this a Script or a LocalScript? BlueTaslem 18071 — 9y
0
Also, what errors did you find when pressing F9 (opening dev console) TheDeadlyPanther 2460 — 9y
View all comments (4 more)
0
@LordDragonZord; it's all about context. This script may be 50 lines long, but a lot of those lines are only setting properties of newly created objects. adark 5487 — 9y
0
@OP; Is this a LocalScript, and is Filtering enabled? adark 5487 — 9y
0
@adark, that's no fair, I deserve those 20+ reputation back. EzraNehemiah_TF2 3552 — 9y
0
@TheDeadlyPanther, There are no errors in the dev console, @ALL This is in a Server Script (normal script), @adark Filtering is disabled. General_Scripter 425 — 9y

2 answers

Log in to vote
1
Answered by 9 years ago

TextBounds cannot be calculated by the server and is not replicated to it either -- you'll have to use a local script to read it. You can observe this behavior in a simple environment by starting a test server with a test player, adding a GUI and a TextLabel to the player's PlayerGui, setting its text to anything, and then looking at the TextBounds property on both the server and client. Also, if you have an old plugin that inserts a NetworkServer to use HTTPService (you no longer need to do this to use HTTPService in plugins), it will break TextBounds because Studio will think it's a server -- this is the way I initially discovered this in fact.

This kind of gotcha should be listed on the wiki, but it isn't. I'll ask someone to add it onto the TextBounds pages for TextBoxes, TextLabels, and TextButtons. Edit: Thank TheGamer101 for adding this to the appropriate pages.

0
How could I actually fix this, I already have everything in 1 script, how could I get a local script to send the data of the text bounds back to the script? Also is it possible to use module scripts to do get text bounds? General_Scripter 425 — 9y
0
Ignore that, I tried it, converted my script to a local script and edited it to work with the change. Thanks for the help! General_Scripter 425 — 9y
0
You might want to edit {Still Unanswered} out of the title now btw EchoReaper 290 — 9y
0
xD Did it, a bit late but at least it won't confuse people. General_Scripter 425 — 9y
Ad
Log in to vote
1
Answered by 8 years ago

What the guy that answered said!

Answer this question