Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Changing gui text with remote events?

Hi, I've been trying to use remote events to change gui texts but none of my scripts will work. Can you help and explain why it won't work?

--// Server Script
local event = Instance.new("RemoteEvent")
event.Parent = game.Workspace
event.Name = "MyServerEvent"
game.Workspace.MyServerEvent:FireAllClients()


--// Local Script
local client = game:GetService("Players").LocalPlayer
local playergui = client.PlayerGui
game.Workspace.MyServerEvent.OnClientEvent:connect(function()
	playergui.ScreenGui.TextLabel.Text = "testing"
end)

1 answer

✓ Accepted answer

The Problem

local client = game:GetService("Players").LocalPlayer

^ You'd have to do the GetService() separately. You can't get the child after you've called the instance on the same line, which is GetService(), so if you still want to GetService() of the service 'Players' look below.

Replace that with...

local players = game:GetService("Players")
local client = players.LocalPlayer

^ This calls the instance AND gets the LocalPlayer, the below line of code is also is another way to do this. But the above code is more efficient.

For now I'll use this..

local client = game.Players.LocalPlayer

Final Product:

--// Server Script
local event = Instance.new("RemoteEvent")
event.Parent = game.Workspace
event.Name = "MyServerEvent"
game.Workspace.MyServerEvent:FireAllClients()


--// Local Script
local client = game.Players.LocalPlayer
local playergui = client.PlayerGui
local event = game.Workspace:FindFirstChild("MyServerEvent")

event.OnClientEvent:connect(function()
    playergui.ScreenGui.TextLabel.Text = "testing"
end)

Hope it works! :)

2 comments

0

All it's saying is that ScreenGui is not a valid member of playergui. Do you know why?

0

Make sure that's where the Screengui is.. and make sure it's called "ScreenGui". If you're inserting it from a script, pm me the script via roblox, if not.. then that should be the problem (misplacement and/or the name)

This discussion is preserved as it was. New answers, comments, and votes are closed.