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 textlabels text not change?

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)

7 comments

0

r u using a local script or a server script?

0

Normal script

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

0

Wrong

0

It's says that "ScreenGui is not a valid member of PlayerGui"

0

What do you mean "Wrong"? You just took my comment and made it into an answer.

1 answer

✓ Accepted answer

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

1 comment

0

I'll see if it works

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