This is the part that i cant solve the problem:
remotes.BuyItem.OnServerEvent:Connect(function(player, itemName) local priceItem = game.ServerStorage.Items[itemName] local price = priceItem.Price.Value local coins = player.PlayerData:WaitForChild("Coins") -- Under here is the problem if coins >= price then coins = coins - price
The error i get is: ****bad argument #2 to '?' (string expected, got Object)
Could someone tell me what failed and how to fix it?
You are comparing a number value with a object value, do this
remotes.BuyItem.OnServerEvent:Connect(function(player, itemName) local priceItem = game.ServerStorage.Items[itemName] local price = priceItem.Price.Value local coins = player.PlayerData:WaitForChild("Coins") -- Under here is the problem if coins.Value >= price then coins.Value = coins - price
or you can do
remotes.BuyItem.OnServerEvent:Connect(function(player, itemName) local priceItem = game.ServerStorage.Items[itemName] local price = priceItem.Price.Value local coins = player.PlayerData:WaitForChild("Coins") coins = coins.Value -- Under here is the problem if coins >= price then coins = coins - price
also, dont forget to end BuyItem.OnServerEvent and if statement! if this helped mark this as correct :D