Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Changing gui text with remote events?

Asked by 8 years ago

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

Log in to vote
0
Answered by
legosweat 334 Moderation Voter
8 years ago

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! :)

0
All it's saying is that ScreenGui is not a valid member of playergui. Do you know why? docrobloxman52 407 — 8y
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) legosweat 334 — 8y
Ad

Answer this question