Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why does the textlabels text not change?

Asked by 5 years ago

The text is updating but not showing it on screen.

script.Parent.Touched:Connect(function(hit)
    if hit.Name == "Collectable" then
        game.Workspace.Money.Value = game.Workspace.Money.Value + hit.Value.Value
        game.StarterGui.ScreenGui.TextLabel.Text = "Money: "..game.Workspace.Money.Value
        hit:Destroy()
    end
end)
0
r u using a local script or a server script? XviperIink 428 — 5y
0
Normal script mads090 4 — 5y
0
Yes that's the problem, GUIs are handled on the client, server scripts can't see PlayerGui's descendants. Also you should be changing the GUI in PlayerGui not StarterGui GoldAngelInDisguise 297 — 5y
0
Wrong DeceptiveCaster 3761 — 5y
View all comments (3 more)
0
It's says that "ScreenGui is not a valid member of PlayerGui" mads090 4 — 5y
0
What do you mean "Wrong"? You just took my comment and made it into an answer. GoldAngelInDisguise 297 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

You should be using a LocalScript and accessing the PlayerGui:

script.Parent.Touched:Connect(function(hit)
    local plr = game.Players.LocalPlayer
    if hit.Name == "Collectable" then
        game.Workspace.Money.Value = game.Workspace.Money.Value + hit.Value.Value
        plr.PlayerGui.ScreenGui.TextLabel.Text = "Money: "..game.Workspace.Money.Value
        hit:Destroy()
    end
end)

If you want to access the PlayerGui from a normal script, learn how to use RemoteEvents. (Despite this, there is a bug that enables you to access the PlayerGui through a normal script without using RemoteEvents. Why? I have no idea.)

0
I'll see if it works mads090 4 — 5y
Ad

Answer this question