Hi, I’m trying to change the text of the gui every time a new round starts but the gui does not update, you have to reset to see the new text. I appreciate any help
Script:
local value = script.Parent.Value
local function onvalue(new)
script.Parent.Text = "Round "..new
end
value.Changed:Connect(onvalue)
script.Parent.Text = "Round "..value.Value
local value = script.Parent
local function onvalue(new)
script.Parent.Text = "Round "..new
end
value.Changed:Connect(function()
onvalue(value.Value)
end)
script.Parent.Text = "Round "..value.Value
you are using a .Changed event, so anything in the base that was changed will connect with the changed value and give you another result.
To fix this you have to use value:GetPropertyChangedSignal("Value") so you’re able to change the text and avoid receiving errors that the context is not a string.
In other notes, using .Changed Event will give you the name of the property that was changed, so in your statement the “new variable” will give you “Round Value”
You change the StarterGui value not the PlayerGui value for all the clients.
The UI has ResetOnSpawn set to true.
To fix the issue you have 3 options:
Use remotes - If you use remotes the client will have to send a request to the server when their UI loads and listen to the server sending them requests when the value changes.
Directly modifying the value - You can change the StarterGui value and also loop through all the players currently in the game and change the PlayerGui value on the server, this will replicate to them.
You can parent the value in ReplicatedStorage, so all the changes the server makes to it replicate to the client.
I think option 3 is the easiest to implement since you don’t have to modify anything other than changing the Value parent to ReplicatedStorage:
local val = game.ReplicatedStorage.Value
function onChanged(value)
script.Parent.Text = "Round "..value
end
onChanged(val.Value)
val.Changed:Connect(onChanged)
and of course change that in your server script as well.