Server to Client Event

I am trying to update the text of a gui with the text received by httpservice.

My problem is the text wont update(I am able to receive the text from httpservice but cant put it on textbox)

Script

local ReplicatedStorage = game:GetService(“ReplicatedStorage”)

local RemoteEvent = ReplicatedStorage.Events.loadUpdates

local url = “https://pastebin.com/raw/JEBxjuZz

local pastebinText = game:GetService(“HttpService”):GetAsync(url, true)

game.Players.PlayerAdded:Connect(function(player)

RemoteEvent:FireClient(player,pastebinText)

end)

Local Script

local ReplicatedStorage = game:GetService(“ReplicatedStorage”)

local RemoteEvent = ReplicatedStorage.Events.loadUpdates

local player = game.Players.LocalPlayer

RemoteEvent.OnClientEvent:Connect(function(pastebinText)

script.Parent.Parent.WelcomeFrame.WelcomeText.Text = pastebinText

end)

I’ve just set up a system like this on my end and everything works fine, the only differences I’ve changed to your code is I’ve used :WaitForChild(string name, int maxYieldTime) on the events folder and the remote event.

https://developer.roblox.com/en-us/api-reference/function/Instance/WaitForChild

:WaitForChild(string name, int maxYieldTime) yields/pauses the script until it knows an object named ‘name’ exists. There’s a second parameter which specifies how long :WaitForChild() should run until it just skips attempting to find the object you’re looking for. At a guess in this case, I’d have said that it couldn’t find the RemoteEvent object, for it to :FireClient() on the server, along with binding a .OnClientEvent on a LocalScript.

Below I have the script and localscript that worked for me, along with a picture of my explorer and workspace (I had to replicate the script.Parent.Parent.WelcomeFrame.WelcomeText hierarchy you had, which is why the localscript is in a folder called ‘Parent’, so I do apologise for that).

Script:

local RS = game:GetService("ReplicatedStorage")
local PS = game:GetService("Players")
local HTTPS = game:GetService("HttpService")

local EventsFolder = RS:WaitForChild("Events")
local LoadUpdatesEvent = EventsFolder:WaitForChild("loadUpdates")

local url = "https://pastebin.com/raw/JEBxjuZz"
local pastebinText = HTTPS:GetAsync(url, true)

PS.PlayerAdded:Connect(function(player)
    LoadUpdatesEvent:FireClient(player, pastebinText)
end)

LocalScript:

local RS = game:GetService("ReplicatedStorage")
local HTTPS = game:GetService("HttpService")

local EventsFolder = RS:WaitForChild("Events")
local LoadUpdatesEvent = EventsFolder:WaitForChild("loadUpdates")

LoadUpdatesEvent.OnClientEvent:Connect(function(text)
    script.Parent.Parent.WelcomeFrame.WelcomeText.Text = text
end)

Explorer and workspace:

Explorer

I hope I could be of help! If you have any questions, let me know :smiley:

EDIT: If you’re wondering why my workspace screenshot shows the WelcomeText being ‘N/A’, I needed a placeholder to ensure I knew it changed. :joy:

Does it not work in studio? I replicated everything you did and the results show nothing.(and yes I have http service enabled and studio api)

Yeah, I did the tests in studio but I didn’t try a published place actually. I can’t think of any ideas as to why it doesn’t work then.

All I can suggest is make a new place, enable HTTPService on it and replicate everything onto that place. I can’t think of anything else it could be, my apologies.

It seems like the server is firing the remote before the client gets a chance to start listening, since it only starts listening after the gui has been set up, and the remote is fired as soon as the player joins the server.

Try making the client decide when the server should send the text, by using a RemoteFunction instead, and invoking from the client to wait on the server to return the text.

1 Like