I can't change this GUI from inside a function in my script. No errors are being thrown

I’m trying to edit the text of a screen GUI inside of my PlayerGui when I activate a proximity prompt. When I use the prompt, nothing happens, I’ve printed stuff from it fine, it’s like it just ignores the line that edits the Gui. I’ve used the same line in the command bar (substituting “plr” with “game.Players.Infernecrosis”) and it works fine. Trying this line outside of the function also works fine.

script.Parent.Triggered:Connect(function(plr)
	script.Parent.Parent.Transparency = 1
	script.Parent.Enabled = false
	if tonumber(plr.PlayerGui.hunger.TextLabel.Text) <= 80 then
		plr.PlayerGui.hunger.TextLabel.Text = plr.PlayerGui.hunger.TextLabel.Text + 20
	else
		plr.PlayerGui.hunger.TextLabel.Text = "100"
	end
	task.wait(180)
	script.Parent.Parent.Transparency = 0
	script.Parent.Enabled = true
end)

1 Like

You can’t modify the player’s GUI from a server script, Consider using a remote event and a local script instead

2 Likes

Thanks for the response. I tried using a local script for it, but it still has the exact same problem. Also, are you sure I can’t change the player’s GUI for a server script? Because I used the same line outside of the function, and it was able to modify it.

What is the original text of the TextLabel? is it “100”? if so, does the TextLabel ever go below 80? Also, UI elements ARE modifiable by the server AND they replicate to the client.

2 Likes

Yes, the original text is “100”. The number slowly goes down by 1 every 5 seconds. I’ve tested it below 80 as well, and it still does nothing.

Does the text going down every 5 seconds get changed by the client or the server?

1 Like

It’s changed by the client. Do I need to have it be changed by a server script?

Yes. Changes made on the client do not replicate to the server with UI elements in PlayerGui, but server changes replicate to the client.

1 Like

Ok, thank you. That might be the problem, I’m not sure how I didn’t think about that when I was making this.

Ok, that fixed it. Thanks for your help.

1 Like