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

Why does the text in a ScreenGUI not change but it prints that it has changed?

I wrote a code to change the text of the ScreenGui according to the text on a SurfaceGui but it doesn't work

local buttonLeft = game.Workspace.Entries.LeftEnter --Part in the workspace
local leftValue = game.Workspace.LeftRoad.Truck.Value --BoolValue
local CounterLeft = game.Workspace.Counters.LeftCounter.SurfaceGui.Count
local LeftCountVal = game.Workspace.LeftRoad.Count --IntValue
local GuiCount = game:GetService("StarterGui").TruckEntered.PeopleTruck.PeopleNumber --textbox of the ScreenGui

if leftValue == true then --finding out if there is a vehicle on the left road
	local debounce = true
	buttonLeft.Touched:Connect(function(plr)
		if plr.Parent:FindFirstChild("Humanoid") then
			if debounce == true then
				LeftCountVal.Value = LeftCountVal.Value +1 --Value goes up
				debounce = false
				print(GuiCount.Text) -- prints "0"
				CounterLeft.Text = LeftCountVal.Value
				GuiCount.Text = CounterLeft.Text --text stays as 0
				print(GuiCount.Text) --prints"1"
				wait(0.5)
				debounce = true
			elseif debounce == false then
				LeftCountVal.Value = LeftCountVal.Value
			end
		end
	end)
end

The text on the ScreenGui stays as 0

The text that is printed goes up to 1

Now i changed it a little and an error pops up saying

18:38:26.094 - GetPlayerFromCharacter is not a valid member of Model

This is the new script

if leftValue == true then
	local debounce = true
	buttonLeft.Touched:Connect(function(hit)
		if hit.Parent:FindFirstChild("Humanoid")then
			if debounce == true then
				LeftCountVal.Value = LeftCountVal.Value +1
				debounce = false
				local player = hit.Parent:GetPlayerFromCharacter()
				player.PlayerGui.TruckEntered.PeopleTruck.PeopleNumber = LeftCountVal.Value
				CounterLeft.Text = LeftCountVal.Value
				wait(0.5)
				debounce = true
			elseif debounce == false then
				LeftCountVal.Value = LeftCountVal.Value
			end
		end
	end)
end

Btw this is in ServerScriptService What is the problem here?

2 comments

0

You're altering the StarterGui, which has no affect on the player's screen. You have to change it through the player's PlayerGui.

0

This is a local script right?

1 answer

✓ Accepted answer

This is because you are trying to edit the StarterGui version of the UI.

If you edit anything in the StarterGui, it won't reflect the changes til you reset or move it to the player gui. That's why it's called the StarterGui.

To fix this, make the change to the players PlayerGui.

If this is a server script, it'll be a little tricky to get access to the players GUI but not impossible. If this script is a local, it's very easy.

6 comments

0

So, how do i put the Gui in PlayerGui?

0

Do i Clone it into the player Gui?

1

All guis in starter gui are cloned into player gui automatically when the player joins. it is located game.Players.playername.PlayerGui. Modify it from there

1

I agree with Proq, constantly cloning the ui in startergui to playergui would get annoying and not needed. Just get the plrs playergui and modify the gui from there. You'll save a lot of time.

0

mhm

0

I tried getting player's PlayerGui and an error popped up. I edited my question, please look at it

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