Help in Buy All button

Well first you can check if the tool actually exists, so after line 7 try adding a print(tool), if it doesn’t return anything then you can check if the player’s Ownedtools is also in the shared tools (in this case if your player has a tool named something other than “Block” then you should probably create a copy of that tool and put it into the folder “Tools”, basically your script is checking if every tool you own is in the tools folder)

sorry for the bad wording lol I’m bad at explaining stuff

i have done what u said and it is printing nil

That means that you own a tool that isn’t in the tools folder, try making a copy of the tool you have and putting it into the tools folder

I had done it already but it still doesn’t work and shows the same error, if u want I can screen shot it


Help i did what u said ;-;

This text will be blurred

Update: Still can’t find a solution to this

Is it still printing nil? (also try printing v.Name to see if maybe the problem is still somewhere within the name)

it doesn’t print anything whatsoever

local ds = game:GetService("DataStoreService")
local dsstore = ds:GetDataStore("Toolsystem")

game.ReplicatedStorage.Remotes.BuyAll.OnServerEvent:Connect(function(plr)
	local highest = 1
	for i,v in pairs(plr.Ownedtools:GetChildren()) do
		local tool = game.ReplicatedStorage.Shared.Tools:FindFirstChild(v.Name)
		print(tool)
		if tool.order.Value > highest then
			highest = tool.order.Value
		end
	end
	print("cool")
	local nextnumber = highest +1
	local done = false
	for i, v in pairs(game.ReplicatedStorage.Shared.Tools:GetChildren()) do
			if v:FindFirstChild("order") then
				if v.order.Value == nextnumber  then
					if plr.leaderstats.Coins.Value >= v.Cost.Value then
						local bool = Instance.new("BoolValue")
						bool.Name = v.Name
						bool.Parent = plr.Ownedtools
						nextnumber = nextnumber +1
					else
						done = true
						
					end
				else
					if game.ReplicatedStorage.Shared.TotalTools.Value < nextnumber  then
						done = true
						
					end
				end
			end
		end
	
	local purchased = {}
	if nextnumber-1>highest then
		for i , name in pairs(plr.Ownedtools:GetChildren()) do
			table.insert(purchased , name.Name)
		end
		dsstore:SetAsync(plr.UserId, purchased)
		print("Doing save lol")
	end
	print("YES")
	local item
	for i,v in pairs(game.ReplicatedStorage.Shared.Tools:GetChildren()) do
		if v.order.Value == nextnumber-1 then
			item = v.Name
			local item2 = v:Clone()
			item2.Parent = plr.Backpack
			v:Destroy()
		end
	end
	game.ReplicatedStorage.Remotes.BUYTOOL:FireClient(plr , item)
end)

Just to make sure, you have enough currency for the buy all button to work right?

yes i have enough currency for the buy all button

You made sure to give yourself the currency from the server right? If it was done locally then the server sees that you don’t have any coins even though on your screen it may seem you have 9.99 million.

i gave it through the server only.

im sorry for asking but is script still same to your game right now?
if then ill try to simulation and see the point

Yes the script is same.

This text is blurred

i try your code and add try add something in my simulation: and it make my tool to purchased completedly list

old
at line 16
for i, v in pairs(game.ReplicatedStorage.Shared.Tools:GetChildren()) do
	...
end
replace with
for i, v in pairs(game.ReplicatedStorage.Shared.Tools:GetChildren()) do
	for i, v in pairs(game.ReplicatedStorage.Shared.Tools:GetChildren()) do
		...
	end
end

and the another one is clone tool and add to player inventory:

old
at line 48
if v.order.Value == nextnumber-1 then
replace with
if v.order.Value > highest then

I hope this helps and I’m sorry. I’m not good at grammar

Hi it works but the tool doesnt get destroyed. I wrote the code for that in line 54

(my mistake editing this post)
so… your meaning is that the player only has 1 lastest tool that the player can afford, right?
the previous tool will be destroyed after the player acquires the new tool.

Yes indeed, that is what i want