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

How do i change a text label Publicly?

Asked by 5 years ago

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)
0
gui objects are cloned locally theking48989987 2147 — 5y
0
also, sending the localplayer when doing FireServer is unnecessary, as OnServerEvent has a built in player parameter theking48989987 2147 — 5y
0
Yeah, since GUIs are local you would have to fire all of the clients to update their GUI. AvatarAang400 35 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago

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)
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. natonator63 29 — 5y
0
Oops. Connect FireClient() to PlayerAdded then it will work. DeceptiveCaster 3761 — 5y
Ad

Answer this question