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

Text is shown in properties but not in the GUI?

Asked by 5 years ago

So I came back to scripting and got some progress on some game. I'm trying to change text in a GUI to correspond with a value and it works in properties, but the text doesn't show on the GUI.

CODE:

01local earned = false
02script.Parent.Touched:Connect(function()
03    if earned == false then
04        game.StarterGui.PointGUI.Value.Value = game.StarterGui.PointGUI.Value.Value + 1
05        game.StarterGui.PointGUI.TextLabel.Text = "Point Count: ".. game.StarterGui.PointGUI.Value.Value
06        print("1")
07        earned = true
08    else
09        print("Already gained")
10    end
11end)

2 answers

Log in to vote
0
Answered by 5 years ago

You are changing the property for the gui in the startergui, not the playergui. If a new player were to join, they would see the correct text, but it would not change. I would try

01local earned = false
02script.Parent.Touched:Connect(function(hit)
03    if hit.Parent.Parent:FindFirstChild("Humanoid") ~= nil then
04        local plr = game.Players:FindFirstChild(hit.Parent.Name)
05        if earned == false then
06         plr.PlayerGui.PointGUI.Value.Value = plr.PlayerGui.PointGUI.Value.Value + 1
07         plr.PlayerGui.PointGUI.TextLabel.Text = "Point Count: ".. plr.PlayerGui.PointGUI.Value.Value
08         print("1")
09         earned = true
10         else
11          print("Already gained")
12       end
13    end
14end)
0
Slipped my mind, but uh "Workspace.TestPart.Script:6: attempt to index local 'plr' (a nil value)" DuckMaster11211 13 — 5y
0
local plr = hit.Parent.Parent:FindFirstChild("Humanoid").Parent Coratite 30 — 5y
Ad
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

Well as coratite said You are changing the property for the gui in the startergui, not the playergui. but go to part that you want to touch the player to earn points then insert script(serverside). Type this lines.

01-- Identifying variables
02local earned = false
03function touch(hit)
04   if game.Players:FndFirstChild(hit.Parent.Name) ~= nil then
05      player = game.Players[hit.Parent.Name]
06      if not earned then -- you can use this but you can change the  not earned  to earned == false
07      earned = true
08      player.PlayerGui.PointGUI.Value.Value = player.PlayerGui.PointGUI.Value.Value + 1
09      player.PlayerGui.PointGUI.TextLabel.Text = "Point Count: "..player.PlayerGui.PointGUI.Value.Value
10   print(1)
11  earned = false
12  else
13  print("Already Gained")
14  end
15end
16end

that it .Sorry for indentions and grammers but try it.

Answer this question