Hello There!
so i have a problem which when i join a game it duplicates the tool i have.
there is only TWO ways that this is happening but since im new to scripting i dont know which
and how to fix it so here are the ways:
1.is there is a bug in the starter pack
and lastly 2.is there is a problem with my datastore script
here. its a normal script and its on “ServerScriptService”
local dataStoreService = game:GetService("DataStoreService")
local dataStore = dataStoreService:GetDataStore("Inventory2")
game.Players.PlayerAdded:Connect(function(player)
pcall(function()
local tool = dataStore:GetAsync("User-"..player.UserId)
if tool then
for i,v in pairs(tool) do
local toolfound = game.ReplicatedStorage.Items:FindFirstChild(v)
if toolfound then
toolfound:Clone().Parent = player.Backpack
toolfound:Clone().Parent = player.StarterGear
end
end
end
end)
end)
game.Players.PlayerRemoving:Connect(function(player)
pcall(function()
local toolSave = {}
for i, tool in pairs(player.Backpack:GetChildren()) do
if tool then
table.insert(toolSave,tool.Name)
end
end
dataStore:SetAsync("User-"..player.UserId,toolSave)
end)
end)
Basically StarterGear is like StarterPack except for an individual player. So whenever a tool is added to the StaterGear folder it will clone them to the Backpack. If you want your tools to save when the player dies use StaterGear but if you want them to go away when they die use Backpack.
i tried to edit the script is this right tho??
well i just added a delete
local dataStoreService = game:GetService("DataStoreService")
local dataStore = dataStoreService:GetDataStore("Inventory2")
game.Players.PlayerAdded:Connect(function(player)
pcall(function()
local tool = dataStore:GetAsync("User-"..player.UserId)
if tool then
for i,v in pairs(tool) do
local toolfound = game.ReplicatedStorage.Items:FindFirstChild(v)
if toolfound then
toolfound:Destroy()
toolfound:Clone().Parent = player.Backpack
toolfound:Clone().Parent = player.StarterGear
end
end
end
end)
end)
game.Players.PlayerRemoving:Connect(function(player)
pcall(function()
local toolSave = {}
for i, tool in pairs(player.Backpack:GetChildren()) do
if tool then
table.insert(toolSave,tool.Name)
end
end
dataStore:SetAsync("User-"..player.UserId,toolSave)
end)
end)
```lua