Error leaderstats

Im trying to do a buy event from my shop but i keep getting an error when i try to add an item from data (Name of my leaderstat) to the player. If you could help me, i would apprciate it.

Here is the error: ServerScriptService.Buy/Sell Manager:43: attempt to perform arithmetic (add) on nil and string - Server - Buy/Sell Manager:43.

here is the script:

BuyShopEvent.OnServerEvent:Connect(function(player, ShopItemPrice, ItemToGet, QuantityToGet)

	if player.Data.Coins.Value >= ShopItemPrice.Value then
		player.Data.Coins.Value -= ShopItemPrice.Value
		player.Data[ItemToGet].Value = ItemToGet.Value +QuantityToGet

	end
end)
3 Likes

your error is here.

where is the script that defines QuantityToGet?

3 Likes

BuyButton.MouseButton1Click:Connect(function()
local ShopItemPrice = WoodFrame.PriceValue
local ItemToGet = “Wood”
local QuantityToGet = “2”
BuyShopEvent:FireServer(ShopItemPrice, ItemToGet, QuantityToGet)
end)

2 Likes

i see the issue, your trying to find a value of a string,

Remove the .Value from ItemToGet.Value

2 Likes

player.Data[ItemToGet].Value = ItemToGet +QuantityToGet

1 Like

yes, did it work for you? (char limit)

2 Likes

i didnt work, im getting this error: ServerScriptService.Buy/Sell Manager:43: attempt to perform arithmetic (add) on string - Server - Buy/Sell Manager:43

1 Like

Replace with only 2, no string

2 Likes

then it would be a string + number

it’s an issue.

2 Likes

yea but you cant add 2 string together with math

2 Likes

What exactly is [ItemToGet].Value a number or a string?

2 Likes

Still getting an error (char limit)

1 Like

Does Wood even exist in the Data folder (if its a folder, i am just assuming)

2 Likes

try this:

player.Data[ItemToGet].Value = player.Data[ItemToGet].Value + QuantityToGet

there is one thing, you can’t add a String to a number, so i just made it that it adds the player data to QuantityToGet.

1 Like

yes it xdoes exist in data folder

Show the Folder, wanna see how it looks like

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.