Text bug in GUI

I have a problem with textboxes and texts in GUI generally. The text of them is not defined by the script and is always bugging and the condition where “Write the message and reciever!” even though I entered everything.

Send - Roblox Studio2022-06-0898odb_09_55_13

Here is the “Send” script:

tbox = script.Parent.Parent.TextBox.Text
treciever = script.Parent.Parent.receiver.Text
txt = script.Parent.TextLabel

script.Parent.MouseButton1Click:Connect(function()
    if tbox ~= "" and treciever ~= "" then
        local msg = script.Parent.Parent.TextBox
        local recipient = script.Parent.Parent.Recipient
        local sender = game.Players.LocalPlayer
        game.ReplicatedStorage.RemoteEvent:FireServer(msg.Text, recipient.Value, sender.Name)
        tbox = ""      
        if not script.Parent.Parent.NameLock.Value then treciever = "" end
        script.Parent.Parent.TextBox.PlaceholderColor3 = Color3.fromRGB(0, 178, 0)
        script.Parent.Parent.TextBox.PlaceholderText = "Sent"
        wait(1.5)
        script.Parent.Parent.TextBox.PlaceholderText = "Message..."
        script.Parent.Parent.TextBox.PlaceholderColor3 = Color3.fromRGB(178, 178, 178)


    elseif tbox == "" and treciever ~= "" then
        txt.TextColor3 = Color3.new(1, 0, 0)
        txt.Text = "Write the message!"
        wait(1)
        txt.TextColor3 = Color3.new(0, 0, 0)
        txt.Text = "Send"


    elseif tbox == "" and treciever == "" then
        txt.TextColor3 = Color3.new(1, 0, 0)
        txt.Text = "Write the message and choose receiver!"
        wait(1)
        txt.TextColor3 = Color3.new(0, 0, 0)
        txt.Text = "Send"


    elseif treciever == "" and tbox ~= "" then
        txt.TextColor3 = Color3.new(1, 0, 0)
        txt.Text = "Choose receiver!"
        wait(1)
        txt.TextColor3 = Color3.new(0, 0, 0)
        txt.Text = "Send"
    end
end)

I tried with ‘’ instead of “”, still didn’t help

And I don’t know how to make the conditions simpler and more compact, so I did it for each case

You are saving the text of the textbox and the receiver textbox prior to the script which leads to a constant string being saved. To fix this, simply make tbox and treciever only refer to the textbox instance and make them index Text further down the script manually.

tbox = script.Parent.Parent.TextBox
treciever = script.Parent.Parent.receiver

...

script.Parent.MouseButton1Click:Connect(function()
    if tbox.Text ~= "" and treciever.Text ~= "" then
1 Like

I didn’t quite understand what you mean :frowning:

try changing it to textbox and reciever only and adding .text down

the text wont change since its defined already, u need to “re-define” it when the button is clicked

basically something like this

tbox = script.Parent.Parent.TextBox  --// changed here
treciever = script.Parent.Parent.receiver  --// changed here
txt = script.Parent.TextLabel

script.Parent.MouseButton1Click:Connect(function()
    if tbox.Text ~= "" and treciever.Text ~= "" then  --// changed here
        local msg = script.Parent.Parent.TextBox
        local recipient = script.Parent.Parent.Recipient
        local sender = game.Players.LocalPlayer
        game.ReplicatedStorage.RemoteEvent:FireServer(msg.Text, recipient.Value, sender.Name)
        tbox = ""      
        if not script.Parent.Parent.NameLock.Value then treciever = "" end
        script.Parent.Parent.TextBox.PlaceholderColor3 = Color3.fromRGB(0, 178, 0)
        script.Parent.Parent.TextBox.PlaceholderText = "Sent"
        wait(1.5)
        script.Parent.Parent.TextBox.PlaceholderText = "Message..."
        script.Parent.Parent.TextBox.PlaceholderColor3 = Color3.fromRGB(178, 178, 178)


    elseif tbox.Text == "" and treciever.Text ~= "" then
        txt.TextColor3 = Color3.new(1, 0, 0)
        txt.Text = "Write the message!"
        wait(1)
        txt.TextColor3 = Color3.new(0, 0, 0)
        txt.Text = "Send"


    elseif tbox.Text == "" and treciever.Text == "" then
        txt.TextColor3 = Color3.new(1, 0, 0)
        txt.Text = "Write the message and choose receiver!"
        wait(1)
        txt.TextColor3 = Color3.new(0, 0, 0)
        txt.Text = "Send"


    elseif treciever.Text == "" and tbox.Text ~= "" then
        txt.TextColor3 = Color3.new(1, 0, 0)
        txt.Text = "Choose receiver!"
        wait(1)
        txt.TextColor3 = Color3.new(0, 0, 0)
        txt.Text = "Send"
    end
end)
1 Like

Thanks, it worked, I thought what functions should be done at the bottom of the script, I don’t know how I didn’t think of this before

your welcome, i forgot to change the other parts, i changed now, in case u wanted to re-copy it or something

1 Like