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 4 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:

local earned = false
script.Parent.Touched:Connect(function()
    if earned == false then
        game.StarterGui.PointGUI.Value.Value = game.StarterGui.PointGUI.Value.Value + 1
        game.StarterGui.PointGUI.TextLabel.Text = "Point Count: ".. game.StarterGui.PointGUI.Value.Value
        print("1")
        earned = true
    else
        print("Already gained")
    end
end)

2 answers

Log in to vote
0
Answered by 4 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

local earned = false
script.Parent.Touched:Connect(function(hit)
    if hit.Parent.Parent:FindFirstChild("Humanoid") ~= nil then
        local plr = game.Players:FindFirstChild(hit.Parent.Name)
        if earned == false then
         plr.PlayerGui.PointGUI.Value.Value = plr.PlayerGui.PointGUI.Value.Value + 1
         plr.PlayerGui.PointGUI.TextLabel.Text = "Point Count: ".. plr.PlayerGui.PointGUI.Value.Value
         print("1")
         earned = true
         else
          print("Already gained")
       end
    end
end)
0
Slipped my mind, but uh "Workspace.TestPart.Script:6: attempt to index local 'plr' (a nil value)" DuckMaster11211 13 — 4y
0
local plr = hit.Parent.Parent:FindFirstChild("Humanoid").Parent Coratite 30 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 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.

-- Identifying variables
local earned = false
function touch(hit)
   if game.Players:FndFirstChild(hit.Parent.Name) ~= nil then
      player = game.Players[hit.Parent.Name]
      if not earned then -- you can use this but you can change the  not earned  to earned == false
      earned = true
      player.PlayerGui.PointGUI.Value.Value = player.PlayerGui.PointGUI.Value.Value + 1
      player.PlayerGui.PointGUI.TextLabel.Text = "Point Count: "..player.PlayerGui.PointGUI.Value.Value
   print(1)
  earned = false
  else
  print("Already Gained")
  end
end
end

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

Answer this question