Howdy.
Guis have never been my strong suit, and I have come across a ridiculously annoying problem that I can’t seem to find the solution to. I’m trying to make the text on a gui (as seen below) change text.

I have included the following scripts:
ReplicatedStorage.

Script to update value. (Inside button.)
local currentLeader = game.ReplicatedStorage.CurrentLeader.Value
script.Parent.MouseButton1Click:Connect(function()
if currentLeader == "NOBODY" then
game.ReplicatedStorage.changeLeader:FireServer()
else
print("There already is a leader!")
end
end)
Script in ServerScriptService.
local changeLeader = game.ReplicatedStorage.changeLeader
local CurrentLeader = game.ReplicatedStorage.CurrentLeader.Value
changeLeader.OnServerEvent:Connect(function(plyr)
CurrentLeader = plyr.Name
end)
Script inside of the string of text. (To update it.)
while wait(1)do
local name = game.ReplicatedStorage.CurrentLeader.Value
script.Parent.Text = "Current leader: "..name
print(name)
end
Currently, I get this as an output, even after activating the button. I receive no errors. Although, it is obvious that most of the script works.

Thanks everyone!
local currentLeader = game.ReplicatedStorage.CurrentLeader.Value
local changeLeader = game.ReplicatedStorage.changeLeader
local CurrentLeader = game.ReplicatedStorage.CurrentLeader.Value
I personally think there’s a bit of inconsistency in your code where either you are defining path Value
early on or just not calling it at all.
Try to call the path within the function to keep it less messy. Like so:
local changeLeader = game.ReplicatedStorage.changeLeader
local CurrentLeader = game.ReplicatedStorage.CurrentLeader
changeLeader.OnServerEvent:Connect(function(plyr)
CurrentLeader.Value = plyr.Name
end)
Also, are you allowing remote requests into your game or is it being blocked in the game settings? It should be under Security and you should so a check option that says something among the lines of “remote events requests.”
EDIT: Okay so I delve deeper into the problem and I got it working in my game. So here’s what to do.
- Make sure you have you “Allow HTTP Requests” switched on in your Game Settings.
- Click save so studio advises that you switched on services to work with RemoteEvents.
So you’ll have to chuck one of the scripts in button, and that’s going to be the while wait(1) loop and you’ll see why.
--LocalScript in TextButton
local player = game.Players.LocalPlayer
local CurrentLeader = game.ReplicatedStorage.CurrentLeader
local changeLeader = game.ReplicatedStorage.changeLeader
script.Parent.MouseButton1Click:Connect(function()
if CurrentLeader.Value == "NOBODY" then
changeLeader:FireServer(script.Parent) --Just referencing the button in the parenthesis.
else
print("There already is a leader!")
end
end)
And then here’s this:
local changeLeader = game.ReplicatedStorage.changeLeader
local CurrentLeader = game.ReplicatedStorage.CurrentLeader
changeLeader.OnServerEvent:Connect(function(player,textbutton) --textbutton is the reference I made in the previous script
CurrentLeader.Value = player.Name
textbutton.Text = "Current leader: " .. CurrentLeader.Value
end)
All seems to be working well for me. Try it on your end.
Tried it out, and it worked! Thank you.
1 Like