Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

so my Roblox inventory save script has an issue with when a player resets it gets all the tools?

Asked by 3 years ago

this is my code

local dss = game:GetService("DataStoreService") local db = dss:GetDataStore("ImCool")

game.Players.PlayerAdded:Connect(function(player) local leaderstats2 = Instance.new("Folder", player) leaderstats2.Name = "leaderstats2"

local ownsTool2 = Instance.new("BoolValue", player)
ownsTool2.Value = false
ownsTool2.Name = "ownsTool2"

local money = Instance.new("NumberValue", leaderstats2)
money.Value = 0
money.Name = "Money"

local ownsTool2Data
local moneyData

local success, errorMessage = pcall(function()
    ownsTool2Data = db:GetAsync(player.UserId.."-ownsTool2")
    moneyData = db:GetAsync(player.UserId.."-money")
end)

if success then
    ownsTool2.Value = ownsTool2Data
    money.Value = moneyData
else
    warn(errorMessage)
end

player.CharacterAdded:Connect(function(char)
    if player.ownsTool2.Value == true then
        game.ServerStorage.BetaTestingSword:Clone().Parent = player:WaitForChild("Backpack")
        print('gave tool because player owns it')
    else
        print('we didnt give any tool')
    end
end)

end)

game.Players.PlayerRemoving:Connect(function(player)

db:SetAsync(player.UserId.."-ownsTool2", player.ownsTool2.Value)
db:SetAsync(player.UserId.."-money", player.leaderstats2.Money.Value)

end)

this script name is leaderstats its in serverscript service for ever tool i have to copy this file

Answer this question