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