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?
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.