You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve?
i want for the tools number/perk id to be loaded but it does not load -
What is the issue?
the loop command didnt work and does not give error. the prints on the loop didnt print. tried fixing for days -
What solutions have you tried so far?
using coroutines and other things
script is on serverscriptservice
code:
local DataStoreService = game:GetService("DataStoreService")
local toolperk = DataStoreService:GetDataStore("Toolperk9")
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
--local toolsunsort = ]
local toolss = game.ReplicatedStorage.Tools:GetChildren()
local tools = {}
if toolperk:GetAsync(player.UserId) ~= nil then
print(tools)
end
table.remove(toolperk:GetAsync(player.UserId),2)
print(toolperk:GetAsync(player.UserId))
--[[
if toolperk:GetAsync(player.UserId) then
--table.insert(tools,1,toolperk:GetAsync(player.UserId))
for i,v in pairs(toolperk:GetAsync(player.UserId)) do
local count = 0
repeat count += 1 until count >= 100 or table.find(toolperk:GetAsync(player.UserId),toolss[count] )
--for i,v in pairs(toolss) do
-- count += 1
print(toolss[count])
--end
tools[#tools+1] = toolperk:GetAsync(player.UserId)[v]
table.insert(tools,count)
if toolperk:GetAsync(player.UserId) ~= nil then
table.remove(tools,2)
print(tools)
end
end
else
tools = {}
end
--]]
if toolperk:GetAsync(player.UserId) then
for i,v in pairs(toolperk:GetAsync(player.UserId)) do
--table.insert(tools,#tools + 1,toolperk:GetAsync(player.UserId)[i])
tools[#tools + 1] = toolperk:GetAsync(player.UserId)[i]
--toolperk:GetAsync(player.UserId)
end
else
tools = {}
end
if toolperk:GetAsync(player.UserId) ~= nil then
print(tools)
end
--repeat wait() until tools
character.ChildAdded:Connect(function(tool)
if tool:FindFirstChild("perkid") then print(tool.Name)
tool:FindFirstChild("perkid").Changed:Connect(function()
if tool:FindFirstChild("perkid").Value == 1 then
local count = 0
repeat count += 1 until toolss[count].Name == tool.Name
tools[#tools + 1] = count table.sort(tools)--table.insert(tools,#tools + 1,tool.Name)
print(game.ReplicatedStorage.Tools:GetChildren()[count])
print(tools)
--toolperk:SetAsync(player.UserId,tool.Name)
for i,v in pairs(tools) do
toolperk:SetAsync(player.UserId,tools)
end
print("saved")
end
end)
end
end)
player:WaitForChild("Backpack").ChildAdded:Connect(function(tool)
print(tool.Name)
if tool:FindFirstChild("perkid") then
tool:FindFirstChild("perkid").Changed:Connect(function()
if tool:FindFirstChild("perkid").Value == 1 then
local count = 0
repeat count += 1 until toolss[count].Name == tool.Name
tools[#tools + 1] = count table.sort(tools)--table.insert(tools,#tools + 1,tool.Name)
print(game.ReplicatedStorage.Tools:GetChildren()[count])
print(tools)
--toolperk:SetAsync(player.UserId,tool.Name)
for i,v in pairs(tools) do
toolperk:SetAsync(player.UserId,tools)
end
print("saved")
end
end)
end
end)
for i,v in pairs(character:GetChildren()) do
repeat wait() until v:FindFirstChild("perkid")
v:FindFirstChild("perkid").Changed:Connect(function()
if v:FindFirstChild("perkid").Value == 1 then
local count = 0
repeat count += 1 until toolss[count].Name == v.Name
tools[#tools + 1] = count--table.insert(tools,#tools + 1,tool.Name)
print(tools)
--toolperk:SetAsync(player.UserId,tool.Name)
for i,v in pairs(tools) do
toolperk:SetAsync(player.UserId,tools)
end
print(tools[count])
print("saved")
end
end)
end
for i,v in pairs(player:WaitForChild("Backpack"):GetChildren()) do
if v:FindFirstChild("perkid") then
v:FindFirstChild("perkid").Changed:Connect(function()
if v:FindFirstChild("perkid").Value == 1 then
local count = 0
repeat count += 1 until toolss[count].Name == v.Name
tools[#tools + 1] = count--table.insert(tools,#tools + 1,tool.Name)
print(tools)
--table.insert(tools)
--toolperk:SetAsync(player.UserId,tool.Name)
for i,v in pairs(tools) do
toolperk:SetAsync(player.UserId,tools)
end
print("saved")
end
end)
end
end
while wait() do ------ Problem ---------~~~~~~~~
-- This function might do some work for a bit then yield some value
repeat
print("0")
for i,v in pairs(tools) do
print("1")
if toolss[v] ~= nil then
print("2")
local name = toolss[v].Name
print(name)
--print(toolss[v].Name)
if player.Backpack:FindFirstChild(name) then
print("3")
player.Backpack:FindFirstChild(name):WaitForChild("perkid").Value = 1
--player.Backpack:FindFirstChild(name).Name = name.." {upgraded}"
--print(tools)
end
end
end
wait()
until script == nil
end
--[[
for i,v in pairs(toolss) do
if toolperk:GetAsync(player.UserId) and toolperk:GetAsync(player.UserId) ~= nil then
if table.find(tools,v.Name)then
v:WaitForChild("perkid").Value = 1
end
end
end
--]]
end)
end)
you may not understand by my messy scripting, take your time. any help is appreciated