What do I want to achieve? I want to have a responsive buy all button
What is the issue? So lets say, i have 10k coins, but it buys everything in the shop.And it takes a minute or 2 to get the item
What solutions have you tried so far? I learnt more about repeat until loops but i still cant figure out the problem and it shows no error btw
--serverside
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)
if tool.order.Value > highest then
highest = tool.order.Value
end
end
print("cool")
local nextnumber = highest +1
local done = false
repeat
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
until done == true
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:Destory()
end
end
game.ReplicatedStorage.Remotes.BUYTOOL:FireClient(plr , item)
end)
--Client side
script.Parent.MouseButton1Click:Connect(function()
game.ReplicatedStorage.Remotes.BuyAll:FireServer()
print("Fires")
end)
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)
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:Destory()
end
end
game.ReplicatedStorage.Remotes.BUYTOOL:FireClient(plr , item)
end)
The error is basically saying it doesn’t know what “tool” is, so I think the problem is line 7 where you’re trying to find a tool that doesn’t exist, which causes the error to appear when you try to use the variable on line 8.