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
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)
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 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
(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.