Error says something isn't a valid member when it is

Hello I am trying to make a server message system but when it tries to update the gui that displays the server message it says that something is not a valid member…
image

Here are my scripts:
This first one is a local script

local RemoteEvent = game.ReplicatedStorage.ServerMessage
local RemoteEventClient = game.ReplicatedStorage.ServerMessageClient
local ServerMessage = game.Players.LocalPlayer.PlayerGui.ServerMessage.ServerMessageText.Text

script.Parent.MouseButton1Click:Connect(function(Player, message)
	local text = game.Players.LocalPlayer.PlayerGui.TesterMenu.TesterMenu.ServerMessage.ServerMessageText.Text
	message = text
	RemoteEvent:FireServer(tostring(message))
end)

RemoteEventClient.OnClientEvent:Connect(function(Player, message)
	print("Client Recieved")
	local ServerMessageString = tostring(message)
	ServerMessage = ServerMessageString
end)

This one is a server script

local RemoteEvent = game.ReplicatedStorage.ServerMessage
local RemoteEventClient = game.ReplicatedStorage.ServerMessageClient

RemoteEvent.OnServerEvent:Connect(function(Player, message)
	print("Server Recieved")
	RemoteEventClient:FireAllClients(Player, message)
	print("Server Sent")
end)

Here is where the gui that it says isn’t a member is

Have you tried using :WaitForChild()? You might be getting that error due to the fact that the object hasn’t been loaded into the game (or player, for that matter) yet.

Hi, could you send a picture of the playerGui?

I tried it but I’m not sure if I used it in the right place or waited for the right thing. Where should :WaitForChild() go?

1 Like

Use it when you define the variable in the LocalScript.

local ServerMessage = game.Players.LocalPlayer:WaitForChild("PlayerGui"):WaitForChild("ServerMessage"):WaitForChild("ServerMessageText").Text
1 Like

local RemoteEvent = game.ReplicatedStorage:WaitForChild("ServerMessage")

Thanks that worked, but at the bottom of the local script where it sets the text value for the server message I have to do “game.Players.LocalPlayer.PlayerGui.ServerMessage.ServerMessageText.Text” instead of the variable name ServerMessage otherwise it won’t change the text.

1 Like

Try removing the .Text part from the variable and writing it as ServerMessage.Text on that line (and anywhere else where it’s needed). If you define a variable as a property, the variable becomes the value of the property and can’t be changed. I hope that wasn’t too confusing to understand; I haven’t touched Roblox Studio for a while.

1 Like

I was thinking of this but hadn’t tried it yet. It wasn’t too confusing to understand. It works now thanks!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.