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

Why isn't the server script altering GUI text?

I've heard you can use server scripts for GUI but it changes it for every player and that's exactly what I need. I might be wrong though, if I am and I need to be using a ClientFire or ServerFire let me know.

game.Players.PlayerAdded:Connect(function(plr)
while wait() do
		local Sell = game.Workspace.Sell:GetChildren()
		local Street = Sell[math.random(1, #Sell)]
		local Houses = Street:GetChildren()
		local Destination = Houses[math.random(1, #Houses)]

		plr.PlayerGui.Delivery.Address.Text = "Deliver to "..Destination.Name.." "..Street.Name..", BloxyTown"

		Destination.Transparency = 0
		wait(math.random(20,40))
		Destination.Transparency = 1

end
end)

3 answers

I'm not the best with scripts like this, however I think local scripts work best for changing the text of a GUI. That way it does it locally so only the player can see it. I've tried converting some gui scripts from server scripts to local scripts and it went from errors to working.

Add the function :WaitForChild(), that outta do the trick.

game.Players.PlayerAdded:Connect(function(plr)
	while wait() do
		local Sell = game.Workspace.Sell:GetChildren()
		local Street = Sell[math.random(1, #Sell)]
		local Houses = Street:GetChildren()
		local Destination = Houses[math.random(1, #Houses)]

		plr.PlayerGui:WaitForChild("Delivery").Address.Text = "Deliver to "..Destination.Name.." "..Street.Name..", BloxyTown"

		Destination.Transparency = 0
		wait(math.random(20,40))
		Destination.Transparency = 1
	end
end)

Although, I do not recommend having a script change GUI object properties.

To make is so the GUI changed for every player you would need to make a remote event go through local > server > local, you can do this by:

-- in local script
script.remote:FireServer()

-- in server script
script.Parent.OnServerEvent:Connect(function()
	script.Parent:FireAllClients()
end)

-- in local script
script.remote.OnClientEvent:Connect(function()
	text = "lol"
end)

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