Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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

3 comments

0

do you mean the output cause there are no errors

0

What type of Value is EquipedTool?

0

String

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

1 comment

0

so i guess the question is anserd

This discussion is preserved as it was. New answers, comments, and votes are closed.