local item = game.Workspace.Cube
local ClickDetector = item:WaitForChild("ClickDetector")
local fireclientgui = game.ReplicatedStorage.Events.InventoryEvents.FireClientGui
local firepurchasegui = game.ReplicatedStorage.Events.InventoryEvents.FirePurchaseGui
local itemList = require(game.ServerScriptService.Inventory.ItemsModule)
local itemID = item:GetAttribute("ItemID")
local ItemName = itemList[itemID].Name
local ItemPrice = itemList[itemID].Price
local ItemCategory = itemList[itemID].Category
local DataManager = require(game.ServerScriptService.DataStore.Data.DataManager)
ClickDetector.MouseClick:Connect(function(player)
firepurchasegui:FireClient(player, ItemName, ItemPrice)
end)
firepurchasegui.OnServerEvent:Connect(function(player)
local Stack = 0
if player.leaderstats.Coins.Value < ItemPrice then
player.PlayerGui.Inventory.PurchaseFail.Visible = true
task.wait(2)
player.PlayerGui.Inventory.PurchaseFail.Visible = false
else
DataManager.removeCoins(player, ItemPrice)
local ItemCreate = Instance.new("NumberValue")
ItemCreate.Name = itemID
ItemCreate.Parent = player.owneditems
--IMPORTANT PART HERE--
for _, v in pairs (player.owneditems:GetChildren()) do
print(v.Name) --line 31
print(itemID) --line 32
if v.Name == itemID then
Stack += 1
end
end
print(Stack) --line 37
--]]
ItemCreate.Value = Stack
fireclientgui:FireClient(player, ItemName, ItemCategory, itemID, Stack)
player.PlayerGui.Inventory.PurchaseSuccess.Visible = true
task.wait(2)
player.PlayerGui.Inventory.PurchaseSuccess.Visible = false
end
end)
#Help - variable not incrementing?
1 messages · Page 1 of 1 (latest)
The Output when firepurchasegui event is called:
1 - Server - InventoryHandler:31
1 - Server - InventoryHandler:32
0 - Server - InventoryHandler:37
if v.Name is equal to itemID then increment Stack by 1
Stack does not increment
.
The Output when called twice:
1 - Server - InventoryHandler:31
1 - Server - InventoryHandler:32
1 - Server - InventoryHandler:31
1 - Server - InventoryHandler:32
0 - Server - InventoryHandler:37
Stack should print '2' (line 37)
please help
you got to give more detail
sorry i didnt mean to ask in someone elses thread
ok nvm i just need to read it
well you did, but its whatever
ill read
yeah because Stack is reset to 0 every time you call the event
thats fine i want it to be 0
oh right, i see
send the place file if it's small, it'll be easier
how many items are actually in player.ownedItems?
intresting
let me recreate it in another place cuz its in a big game rn
what game
sure
are you making
this is an inventory system
actually don't recreate it yet
lets bug test
add a print after your v.Name == itemID to see if it gets past there
print what the itemID is at the start, and then what it is that you're actually comparing it to
to get a better picture of what's going on
here i actually cloned this post because the first person to help me was not understanding me but i have a bunch of images that will help
the itemID is 1
hold on
Wait
** You are now Level 3! **
is thisa local script?
was
** You are now Level 5! **
in the click detector?
if v.Name == tostring(itemID) then
try that ^
maybe an issue with numbers vs strings
okk yeah when i hover over both its v.Name: any and itemID: any
njot sure if that means much
yk what i usually do?
try it
I onetime got stuck with this for hours
when i wasnt as good with scripting
when i made an amusement park I put in in starterplayerscripts THEN fired to serverscriptservice as an event -
`local userInputService = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
--Variables
---Main Client For Starting Sunburst Express
game.Workspace:WaitForChild("StartTestRide").ClickDetector.MouseClick:Connect(function()
local Speed = game.Workspace.RideTweenScript.Speed
game.ReplicatedStorage.StartRide1:FireServer(Speed.Value)
end)`
legend
fixed it?
works?
it actually works thankyou
banger
yes
oh vcool
lucky not too long about 2 days
since early yesterday
anyone wanna check out my github page
no brother
you know i actually did try
local name = tostring(itemID)
v.Name == name
and that didnt work
really?
so yeah scripting really picky sometimes
this was back on localscript tho
¯_(ツ)_/¯
yeah i think ur right
fr
mustve been the other way around yeah
thats a shame, you were so close to solving it then
lol
I used to think Roblox studio was just not working
something liek that
ryan why are you here
i was also reading over other peoples scripts to see if i could help while waiting
which was why i was in the other thread
cheers again lightlim youre a legend
no prob bob