I've been working on an inventory system and when the player places an item down, the value in their inventory is supposed to decrease. However, this doesn't happen, and I'm not sure why.
The code I'm using:
wait(3) local playername = script.Parent.Parent.PlayerNameTag.Value local haveitem = game.Players:FindFirstChild(playername).Character.OwnedItems.BlueShrine.Value if haveitem == 0 then script.Parent.Parent:Destroy() end if haveitem >= 1 then haveitem = (haveitem - 1) end
The thing is... the script still knows what the value of BlueShrine is, as it still destroys the model when haveitem is 0. Does anybody know a solution? Am I making an obvious mistake?
The problem is that this code will return the value e.g 5 not the object which stores the value in:-
local haveitem = game.Players:FindFirstChil(playername).Character.OwnedItems.BlueShrine.Value
So all you are doing is changing the value of the variable and not the object.
Simple fix to get the object:-
wait(3) local playername = script.Parent.Parent.PlayerNameTag.Value local haveitem = game.Players:FindFirstChild(playername).Character.OwnedItems.BlueShrine if haveitem.Value == 0 then script.Parent.Parent:Destroy() end if haveitem.Value >= 1 then haveitem.Value = (haveitem.Value - 1) end
Hope this helps
You are missing the .Value
if haveitem.Value == 0 then script.Parent.Parent:Destroy() end if haveitem.Value >= 1 then haveitem.Value = haveitem .Value- 1 end