local DataStoreService = game:GetService("DataStoreService")
local SaveData = DataStoreService:GetDataStore("SaveData")
game:GetService("Players").PlayerAdded:Connect(function(Player)
local ToolData = SaveData:GetAsync(Player.UserId)
local Backpack = Player:WaitForChild("Backpack")
local StarterGear = Player:WaitForChild("StarterGear")
if ToolData ~= nil then
for i, v in pairs(ToolData) do
if ToolFolder:FindFirstChild(v) and Backpack:FindFirstChild(v) == nil and StarterGear:FindFirstChild(v) == nil then
ToolFolder[v]:Clone().Parent = Backpack
ToolFolder[v]:Clone().Parent = StarterGear
end
end
end
Player.CharacterRemoving:Connect(function(Character)
Character:WaitForChild("Humanoid"):UnequipTools()
end)
end)
game:GetService("Players").PlayerAdded:Connect(function(Player)
local ToolTable = {}
for i,v in pairs(Player.Backpack:GetChildren()) do
table.insert(ToolTable, v.Name)
end
if ToolTable ~= nil then
SaveData:SetAsync(Player.UserId, ToolTable)
end
end)```
-- Make a variable for Players
local Players = game:GetService("Players")
game:GetService("Players").PlayerAdded:Connect(function(Player)
-- Have to be:
Players.PlayerAdded:Connect(function(Player)
if ToolData ~= nil then
-- Have to be:
if ToolData then
if ToolFolder:FindFirstChild(v) and Backpack:FindFirstChild(v) == nil and StarterGear:FindFirstChild(v) == nil then
-- Have to be:
if ToolFolder:FindFirstChild(v) and not Backpack:FindFirstChild(v) and not StarterGear:FindFirstChild(v) then
Players.PlayerAdded:Connect(function(Player)
-- Have to be:
Players.PlayerRemoving:Connect(function(Player)
if ToolTable ~= nil then
-- Have to be:
if ToolTable ~= {} then
Also I would suggest adding a BindToClose event, that saves players data when the server shuts down.
local Players = game:GetService("Players")
game:GetService("Players").PlayerAdded:Connect(function(Player)
-- Have to be:
Players.PlayerAdded:Connect(function(Player)
if ToolData ~= nil then
-- Have to be:
if ToolData then
if ToolFolder:FindFirstChild(v) and Backpack:FindFirstChild(v) == nil and StarterGear:FindFirstChild(v) == nil then
-- Have to be:
if ToolFolder:FindFirstChild(v) and not Backpack:FindFirstChild(v) and not StarterGear:FindFirstChild(v) then
Players.PlayerAdded:Connect(function(Player)
-- Have to be:
Players.PlayerRemoving:Connect(function(Player)
if ToolTable ~= nil then
-- Have to be:
if ToolTable ~= {} then```
When he said āhave to beā he meant to replace it like this
local DataStoreService = game:GetService("DataStoreService")
local SaveData = DataStoreService:GetDataStore("SaveData")
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(Player)
local ToolData = SaveData:GetAsync(Player.UserId)
local Backpack = Player:WaitForChild("Backpack")
local StarterGear = Player:WaitForChild("StarterGear")
if ToolData then
for i, v in pairs(ToolData) do
if ToolFolder:FindFirstChild(v) and not Backpack:FindFirstChild(v) and not StarterGear:FindFirstChild(v) then
ToolFolder[v]:Clone().Parent = Backpack
ToolFolder[v]:Clone().Parent = StarterGear
end
end
end
Player.CharacterRemoving:Connect(function(Character)
Character:WaitForChild("Humanoid"):UnequipTools()
end)
end)
Players.PlayerRemoving:Connect(function(Player)
local ToolTable
for i,v in pairs(Player.Backpack:GetChildren()) do
if not ToolTable then ToolTable = {} end
table.insert(ToolTable, v.Name)
end
if ToolTable then
SaveData:SetAsync(Player.UserId, ToolTable)
end
end)
I was following a tutorial on YouTube but all my lines matched up to the tutorials one I checked like 4 times I did have this solved but it broke its self when adding a new feature in
Code maybe different because I had to make a other developer forum post it did work but broke after adding something in and the person that helped me was a bit cocky.
local DataStoreService = game:GetService("DataStoreService")
local SaveData = DataStoreService:GetDataStore("SaveData")
local ToolFolder = game:GetService("ServerStorage"):FindFirstChild("SavedTools")
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(Player)
local ToolData = SaveData:GetAsync(Player.UserId)
local Backpack = Player:WaitForChild("Backpack")
local StarterGear = Player:WaitForChild("StarterGear")
if ToolData then
for i, v in pairs(ToolData) do
if ToolFolder:FindFirstChild(v) and not Backpack:FindFirstChild(v) and not StarterGear:FindFirstChild(v) then
ToolFolder[v]:Clone().Parent = Backpack
ToolFolder[v]:Clone().Parent = StarterGear
end
end
end
Player.CharacterRemoving:Connect(function(Character)
Character:WaitForChild("Humanoid"):UnequipTools()
end)
end)
Players.PlayerRemoving:Connect(function(Player)
local ToolTable
for i,v in pairs(Player.Backpack:GetChildren()) do
if not ToolTable then ToolTable = {} end
table.insert(ToolTable, v.Name)
end
if ToolTable then
SaveData:SetAsync(Player.UserId, ToolTable)
end
end)
Ok this broke my animations in the sword and didnāt make the item save either when playing in the real game My output says nothing the animation works in studio though
My code for it to animate this is what seems to have broken it
āAnimateā
if Debounce == false then
Debounce = true
local Humanoid = Tool.Parent:WaitForChild("Humanoid")
local AnimTrack = Humanoid:WaitForChild("Animator"):LoadAnimation(Slash)
AnimTrack.Priority = Enum.AnimationPriority.Action4 --This broke the saving on the last post
AnimTrack:Play()
wait(1)
Debounce = false
end
end)```