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
You're altering the StarterGui, which has no affect on the player's screen. You have to change it through the player's PlayerGui.
This is a local script right?