I want to make a Kill other player for money script that saves. But how can I add a Datastore to my Leaderstat becuase mine rn doesnt work. Thanks
Saving Script
local data = game:GetService("DataStoreService"):GetOrderedDataStore("GetMoney00")
local function SaveData(plr,t)
if plr and t then
data:SetAsync(plr.UserId,t.Value)
end
end
game.Players.PlayerAdded:Connect(function(plr)
Instance.new("Folder",plr).Name = "leaderstats"
local stat
local function Getleaderstats()
wait(0.1)
if not plr:FindFirstChild("leaderstats") then
wait(1.5)
Getleaderstats()
else
stat = plr:WaitForChild("leaderstats")
return true;
end
end
Getleaderstats()
local function CreateStat(class,name,parent)
local i = Instance.new(class)
i.Name = tostring(name)
i.Parent = parent
return i
end
local money = CreateStat("IntValue","Gold",stat)
wait(0.03)
local SavedLevel = data:GetAsync(plr.UserId)
if SavedLevel then
money.Value = SavedLevel
else
money.Value = 1
wait(0.08)
SaveData(plr,money)
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
if plr:FindFirstChild("leaderstats") and plr.leaderstats:FindFirstChild("Gold") then
SaveData(plr,plr.leaderstats["Gold"])
end
end)
if not game:GetService("RunService"):IsStudio() then
game:BindToClose(function()
for _,plr in pairs(game:GetService("Players")) do
if plr:FindFirstChild("leaderstats") and plr.leaderstats:FindFirstChild("Gold") then
SaveData(plr,plr.leaderstats["Gold"])
end
end
wait(10)
end)
end
Kill for Money Script
game.Players.PlayerAdded:connect(function(player)
local folder = Instance.new("Folder",player)
folder.Name = "leaderstats"
local currency = Instance.new("IntValue",folder)
currency.Name = "Gold"
player.CharacterAdded:connect(function(character)
character:WaitForChild("Humanoid").Died:connect(function()
local tag = character.Humanoid:FindFirstChild("creator")
if tag ~= nil then
if tag.Value ~= nil then
local stats = tag.Value:WaitForChild("leaderstats")
