I want to make an NPC say a message that I write in a GUI Text box.
The problem is that when I enter the game, it throws an error saying. Players.manfacemanfrend.PlayerGui.Control.Message.LocalScript:9: attempt to index string with 'Text'
I’ve look everywhere for solutions but there is no category which is even remotely related to this issue.?
The Send Message Button scripts.
The 1st script.
local ChatService = game:GetService("Chat")
local Main = game.Workspace.manfacemanfrend
local Humanoid = Main:FindFirstChildOfClass("Humanoid")
local chatbot = Main
local msg = script.Parent.Parent.Message.Text
local input = msg.Text
function control()
ChatService:Chat(chatbot.Head, msg, ".")
print("government mind control go brrrr")
end
My second Send Button script
local control = script.Parent.controled
script.Parent.MouseButton1Click:Connect(function()
control:FireServer()
print("brain wash moment")
end)
The Text Input box script.
local ChatService = game:GetService("Chat")
local Main = game.Workspace.manfacemanfrend
local Humanoid = Main:FindFirstChildOfClass("Humanoid")
local chatbot = Main
local msg = script.Parent.Parent.Message.Text
local input = msg.Text
do
msg.Text = input
end
The handler script
local Players = game:GetService("Players")
local Main = game.Workspace.Security
local Humanoid = Main:FindFirstChildOfClass("Humanoid")
local chatbot = game.Workspace.Security
local messagebox = script.Parent.Message
local send = script.Parent.Send
local sus = script.Parent.sus
local SayMessage = messagebox.Text
local cs = game:GetService("Chat")
function SayMessage:Chat(Text)
messagebox.Text = tostring(Text)
if Text == "" then
sus.Value = false
else
sus.Value = true
messagebox.Text = Text
cs:Chat(chatbot.Head, "[Controlled]:", Text, Enum.ChatColor.White)
end
end
Can someone explain to me where I went wrong and how I can fix it please?
Additionally you might want to try and compress code into fewer scripts or split different parts of code into their own modules to keep everything neat. Even if it takes longer to write, you can’t put a price on readability.
No I just mean that you having a script for each button, different scripts for handling, etc. can quickly get confusing once you add more code. Organization is key.
local ChatService = game:GetService("Chat")
local Main = game.Workspace.manfacemanfrend
local Humanoid = Main:FindFirstChildOfClass("Humanoid")
local chatbot = Main
local msg = script.Parent.Parent.Message.Text
function control()
ChatService:Chat(chatbot.Head, msg, ".")
print("government mind control go brrrr")
end
local ChatService = game:GetService("Chat")
local Main = game.Workspace.manfacemanfrend
local Humanoid = Main:FindFirstChildOfClass("Humanoid")
local chatbot = Main
local msg = script.Parent.Parent.Message.Text
local input = msg
do
msg.Text = input
end
Also, please look at how the problem is being fixed, rather than just having me change it for you.
You’re calling .Text on the msg variable.
The msg variable is :
local msg = script.Parent.Parent.Message.Text
And you’re calling msg.Text, which is the same as calling .Text.Text
To add on to the support you’ve already got, make sure you filter the message if this will be in a game and other players can use it. If you don’t your game may end up flagged for review or deleted.
If it’s just a small private project, don’t worry about it and continue on.