To give some context, I have a game where players go around picking up ores; like diamonds in this case. Upon joining the game, the new player will get a folder called "orestats" and inside this folder there are a bunch of IntValues to count the player's number of each ore. When the player touches an ore, like a diamond, the script inside the diamond locates the player's IntValue counter for that specific ore and adds one to the counter, before the ore is destroyed.
The part I'm having trouble with is adding 1 to the player's PlayerGui counter. Before the ore is destroyed, the script locates the TextLabel - "DiamondAmount" - inside the player's PlayerGui and changes the text to show the IntValue's (diamond counter's) number. This is to show the player how much of the certain ore they have, since they can't see the IntValue's value while in game. I'm not sure if you can set a TextLabel's Text to an IntValue's value, so I'm not sure why it's not working. Maybe you can help?
This is the script inside the diamond ore that the player picks up upon touching it:
function onTouch(part)
local h = part.Parent:findFirstChild("Humanoid")
if (h~=nil) then
local thisplr = game.Players:findFirstChild(h.Parent.Name)
if (thisplr~=nil) then
local diamondscore = thisplr.orestats:findFirstChild("DiamondNum")
diamondscore.Value = diamondscore.Value + 1
-- This is the part I'm having trouble with:
local diamondcounter = thisplr.PlayerGui.OreInventory.MainBox.DiamondCount.DiamondAmount.Text
diamondcounter = diamondscore.Value
end
script.Parent:Destroy()
end
end
script.Parent.Touched:connect(onTouch)

1 comment
The LocalScript doesn't seem to work for me. Since I'm not good with LocalScripts, do I have to place the LocalScript in a certain area inside the Player or something?