I am attempting to make a power level system for my ship, and I wanted a GUI to say the exact power level. I started off with something very basic, or at least I thought it was basic. The text of the GUI does not set in the function. However, if I move the setText outside of the function, the GUI updates. When the function runs, the power value does increase, but the GUI text is not changed. Any ideas?
power = script.Parent.Power gui = game.StarterGui.ScreenGui.TextBox function powerIncrease() power.Value = power.Value + 1 gui.Text = "Power level: "..power.Value end script.Parent.Add.ClickDetector.MouseClick:connect(powerIncrease)
vs this:
power = script.Parent.Power gui = game.StarterGui.ScreenGui.TextBox function powerIncrease() power.Value = power.Value + 1 end gui.Text = "Power level: "..power.Value script.Parent.Add.ClickDetector.MouseClick:connect(powerIncrease)
You're trying to display text on the regular Gui and not the one native to the player(s). Try this:
power = script.Parent.Power function powerIncrease() for _,i in pairs(game.Players:GetPlayers()) do power.Value = power.Value + 1 i.PlayerGui.ScreenGui.TextBox.Text = "Power level: "..power.Value end end script.Parent.Add.ClickDetector.MouseClick:connect(powerIncrease)
What you chould do is, put a localscript into the StarterGui.ScreenGui.Textbox that goes like this
local textbox = script.Parent local power = --this should lead to wherever your power object is while wait() do textbox.Text = "Power lvl: "..power.Value end
That will keep the text updated according to what the powerlevel is So now you can just worry about updating the value of the power in the other script.