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

How do i change a text label Publicly?

The part where we see the username of the player works fine, but i can not see the actual text.(this works fine locally but not publicly)

--public script
game.ReplicatedStorage.OnEnter.OnServerEvent:Connect(function(x)
for i,v in pairs(game.Players:GetChildren()) do

v.PlayerGui.ScreenGui1.TextLabel.Text = x.PlayerGui.ScreenGui.TextBox.Text

v.PlayerGui.ScreenGui1.TextLabel1.Text = x.Name

end

end)
--local script
script.Parent.MouseButton1Click:Connect(function()

game.ReplicatedStorage.OnEnter:FireServer(game.Players.LocalPlayer)

end)

3 comments

0

gui objects are cloned locally

0

also, sending the localplayer when doing FireServer is unnecessary, as OnServerEvent has a built in player parameter

0

Yeah, since GUIs are local you would have to fire all of the clients to update their GUI.

1 answer

The first thing that you're doing wrong is that you're attempting to send the LocalPlayer over to the server, which is literally impossible to do. LocalPlayer is strictly client-side only and cannot be replicated over the server/client boundary.

The second thing that you're doing wrong is that you're accessing the PlayerGui from the server. This can no longer be done because Roblox has removed Experimental Mode, which means that FE will always be on. You cannot disable it from under game as it now appears as a dummy property and can no longer be toggled on or off.

Here is the fix to both of your scripts:

Server Script

local event = game:GetService("ReplicatedStorage"):WaitForChild("OnEnter")
event:FireClient()

Local Script

local event = game:GetService("ReplicatedStorage"):WaitForChild("OnEnter")
event.OnClientEvent:Connect(function(plr)
    for i, p in pairs(game.Players:GetPlayers()) do
	    p.PlayerGui.ScreenGui1.TextLabel.Text = plr.PlayerGui.ScreenGui.TextBox.Text
	    p.PlayerGui.ScreenGui1.TextLabel1.Text = plr.Name
    end
end)

2 comments

0

When i try it, i get an error saying OnClientEvent can only be used in the client and when i fire it it tells me that argument 1 is missing or nil.

0

Oops. Connect FireClient() to PlayerAdded then it will work.

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