i'm making a Gui shop and i'm trying to find an accessory inside the players character that equals the Equipped Value and Deletes it.
the script is a global script in ServerScriptService.
iv'e looked at it for a long time and can't seem to find the issue.
01 | game.ReplicatedStorage:WaitForChild( "CreateTransactionBag" ).OnServerInvoke = function (player,Item) --this is the triggering function when the players clicked the buy button |
02 |
03 | --CreatTransactionBag is a RemoteFunction |
04 | local gold = game.Players:FindFirstChild(player.Name).leaderstats.Gold |
05 | local cost = game.ServerStorage.ShopFolder.BagShop.ItemModels [ Item ] .Information.Cost |
06 | local Class = game.ServerStorage.ShopFolder.BagShop.ItemModels [ Item ] .Information.Class |
07 |
08 |
09 | print (gold.Value) |
10 | print (cost.Value) |
11 |
12 | if gold.Value > = cost.Value and not game.ServerStorage.PlayerStuff [ player.Name ] .Bags:FindFirstChild(Item) then |
13 | print ( "Test1" ) --prints in testing |
14 | gold.Value = gold.Value-cost.Value |
15 |
You should use Console to examine the errors. You didn't have enough ends in your code to close the if statements. This could've simply been a syntax error.
Here is the fixed code I came up with, let me know if there are any issues.
01 | game.ReplicatedStorage:WaitForChild( "CreateTransactionBag" ).OnServerInvoke = function (player,Item) --this is the triggering function when the players clicked the buy button |
02 | --CreatTransactionBag is a RemoteFunction |
03 | local gold = game.Players:FindFirstChild(player.Name).leaderstats.Gold |
04 | local cost = game.ServerStorage.ShopFolder.BagShop.ItemModels [ Item ] .Information.Cost |
05 | local Class = game.ServerStorage.ShopFolder.BagShop.ItemModels [ Item ] .Information.Class |
06 |
07 |
08 | print (gold.Value) |
09 | print (cost.Value) |
10 |
11 | if gold.Value > = cost.Value and not game.ServerStorage.PlayerStuff [ player.Name ] .Bags:FindFirstChild(Item) then |
12 | print ( "Test1" ) --prints in testing |
13 | gold.Value = gold.Value - cost.Value |
14 |
15 | print (player.HidenStats.EquipedTool.Value) --this is the Equipped Value's location |
EDIT:
On the lines of Destroying the current equipped tool, you can destroy the tool inside of the value, no need to search for it.
01 | game.ReplicatedStorage:WaitForChild( "CreateTransactionBag" ).OnServerInvoke = function (player,Item) --this is the triggering function when the players clicked the buy button |
02 | --CreatTransactionBag is a RemoteFunction |
03 | local gold = game.Players:FindFirstChild(player.Name).leaderstats.Gold |
04 | local cost = game.ServerStorage.ShopFolder.BagShop.ItemModels [ Item ] .Information.Cost |
05 | local Class = game.ServerStorage.ShopFolder.BagShop.ItemModels [ Item ] .Information.Class |
06 |
07 |
08 | print (gold.Value) |
09 | print (cost.Value) |
10 |
11 | if gold.Value > = cost.Value and not game.ServerStorage.PlayerStuff [ player.Name ] .Bags:FindFirstChild(Item) then |
12 | print ( "Test1" ) --prints in testing |
13 | gold.Value = gold.Value - cost.Value |
14 |
15 | print (player.HidenStats.EquipedTool.Value) --this is the Equipped Value's location |
16 | player.HidenStats.EquipedTool.Value:Destroy() |
17 | end |
18 | end |
I found myself a solution!
01 | game.ReplicatedStorage:WaitForChild( "CreateTransactionBag" ).OnServerInvoke = function (player,Item) |
02 |
03 | local gold = game.Players:FindFirstChild(player.Name).leaderstats.Gold |
04 | local cost = game.ServerStorage.ShopFolder.BagShop.ItemModels [ Item ] .Information.Cost |
05 | local Class = game.ServerStorage.ShopFolder.BagShop.ItemModels [ Item ] .Information.Class |
06 |
07 |
08 | print (gold.Value) |
09 | print (cost.Value) |
10 |
11 | if gold.Value > = cost.Value and not game.ServerStorage.PlayerStuff [ player.Name ] .Bags:FindFirstChild(Item) then |
12 | print ( "Test1" ) |
13 | gold.Value = gold.Value-cost.Value |
14 |
15 | if player.Character:FindFirstChild(player.HidenStats.EquipedBag.Value) then |
16 | player.Character:FindFirstChild(player.HidenStats.EquipedBag.Value):Destroy() |
17 | end |
18 | end |
19 | end |