Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

game cant recognise that the name == the Equipped value... Why?

Asked by 6 years ago

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.

game.ReplicatedStorage:WaitForChild("CreateTransactionBag").OnServerInvoke = function(player,Item) --this is the triggering function when the players clicked the buy button

--CreatTransactionBag is a RemoteFunction
    local gold = game.Players:FindFirstChild(player.Name).leaderstats.Gold
    local cost = game.ServerStorage.ShopFolder.BagShop.ItemModels[Item].Information.Cost
    local Class = game.ServerStorage.ShopFolder.BagShop.ItemModels[Item].Information.Class


    print(gold.Value)
    print(cost.Value)

    if gold.Value >= cost.Value and not game.ServerStorage.PlayerStuff[player.Name].Bags:FindFirstChild(Item) then 
print ("Test1")--prints in testing
        gold.Value = gold.Value-cost.Value

            print(player.HidenStats.EquipedTool.Value)--this is the Equipped Value's location

        for i, v in pairs(player.Character:GetChildren())do
            if v.Name == player.HidenStats.EquipedTool.Value then --broken part
                v:Destroy()
                print ("Test2")--dosen't print in testing
            end 
        end

2 answers

Log in to vote
0
Answered by
popeeyy 493 Moderation Voter
6 years ago
Edited 6 years ago

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.

game.ReplicatedStorage:WaitForChild("CreateTransactionBag").OnServerInvoke = function(player,Item) --this is the triggering function when the players clicked the buy button
    --CreatTransactionBag is a RemoteFunction
    local gold = game.Players:FindFirstChild(player.Name).leaderstats.Gold
    local cost = game.ServerStorage.ShopFolder.BagShop.ItemModels[Item].Information.Cost
    local Class = game.ServerStorage.ShopFolder.BagShop.ItemModels[Item].Information.Class


    print(gold.Value)
    print(cost.Value)

    if gold.Value >= cost.Value and not game.ServerStorage.PlayerStuff[player.Name].Bags:FindFirstChild(Item) then 
        print("Test1") --prints in testing
        gold.Value = gold.Value - cost.Value

        print(player.HidenStats.EquipedTool.Value) --this is the Equipped Value's location

        for i,v in pairs(player.Character:GetChildren())do
            if v.Name == player.HidenStats.EquipedTool.Value then  --broken part
                v:Destroy()
                print ("Test2") --dosen't print in testing
            end 
        end
    end
end

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.

game.ReplicatedStorage:WaitForChild("CreateTransactionBag").OnServerInvoke = function(player,Item) --this is the triggering function when the players clicked the buy button
    --CreatTransactionBag is a RemoteFunction
    local gold = game.Players:FindFirstChild(player.Name).leaderstats.Gold
    local cost = game.ServerStorage.ShopFolder.BagShop.ItemModels[Item].Information.Cost
    local Class = game.ServerStorage.ShopFolder.BagShop.ItemModels[Item].Information.Class


    print(gold.Value)
    print(cost.Value)

    if gold.Value >= cost.Value and not game.ServerStorage.PlayerStuff[player.Name].Bags:FindFirstChild(Item) then 
        print("Test1") --prints in testing
        gold.Value = gold.Value - cost.Value

        print(player.HidenStats.EquipedTool.Value) --this is the Equipped Value's location
        player.HidenStats.EquipedTool.Value:Destroy()
    end
end
0
do you mean the output cause there are no errors Nooberton_1 9 — 6y
0
What type of Value is EquipedTool? popeeyy 493 — 6y
0
String Nooberton_1 9 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

I found myself a solution!

game.ReplicatedStorage:WaitForChild("CreateTransactionBag").OnServerInvoke = function(player,Item)

    local gold = game.Players:FindFirstChild(player.Name).leaderstats.Gold
    local cost = game.ServerStorage.ShopFolder.BagShop.ItemModels[Item].Information.Cost
    local Class = game.ServerStorage.ShopFolder.BagShop.ItemModels[Item].Information.Class


    print(gold.Value)
    print(cost.Value)

    if gold.Value >= cost.Value and not game.ServerStorage.PlayerStuff[player.Name].Bags:FindFirstChild(Item) then 
print ("Test1")
        gold.Value = gold.Value-cost.Value

        if player.Character:FindFirstChild(player.HidenStats.EquipedBag.Value)then
            player.Character:FindFirstChild(player.HidenStats.EquipedBag.Value):Destroy()
        end
    end
end

0
so i guess the question is anserd Nooberton_1 9 — 5y

Answer this question