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