is there any way i can add a table to shorten it? lmk please
here’s the code:
-- services
local DSS = game:GetService("DataStoreService"):GetDataStore("PlayerData")
local Players = game:GetService("Players")
-- on player added
Players.PlayerAdded:Connect(function(player)
-- create the folders to store all the save values
local leaderstats = Instance.new("Folder", player)
leaderstats.Name = "leaderstats"
local playerstats = Instance.new("Folder", player)
playerstats.Name = "playerstats"
local playersettings = Instance.new("Folder", player)
playersettings.Name = "playersettings"
-- create save values (bounty, kills, cash, bank)
local bounty, kills = Instance.new("NumberValue", leaderstats), Instance.new("NumberValue", leaderstats)
bounty.Name, kills.Name = "Bounty", "Kills"
bounty.Value, kills.Value = 0, 0
local cash, bank = Instance.new("NumberValue", playerstats), Instance.new("NumberValue", playerstats)
cash.Name, bank.Name = "Cash", "Bank"
cash.Value, bank.Value = 0, 0
-- create settings values
local firstPlay = Instance.new("BoolValue", playersettings) -- will pull up a UI on the first time playing for a user
firstPlay.Name = "FirstPlay"
firstPlay.Value = true
-- saving the player's data
local playerKey = "id_"..player.UserId
local getSaved = DSS:GetAsync(playerKey)
local save1, save2, save3, save4 = kills, cash, bank, firstPlay
if getSaved then
save1.Value, save2.Value, save3.Value, save4.Value = getSaved[1], getSaved[2], getSaved[3], getSaved[4]
end
game.Players.PlayerRemoving:Connect(function(player2) -- makes sure the same player who joined & the same player who left have the same savedata
if player == player2 then
DSS:SetAsync(playerKey, {save1.Value, save2.Value, save3.Value, save4.Value})
end
end)
-- counts player kills
player.CharacterAdded:Connect(function(char)
char.Humanoid.Died:Connect(function()
if char.Humanoid:FindFirstChild("creator") and char.Humanoid:FindFirstChild("creator") ~= nil and char.Humanoid:FindFirstChild("creator").Value ~= nil then
char.Humanoid:FindFirstChild("creator").Value:FindFirstChild("leaderstats").Kills.Value += 1
end
end)
end)
end)
any help would be appreciated, thanks in advance!