You can write your topic however you want, but you need to answer these questions:
- What do you want to achieve? I just want to fix this script that I have for a simulator for stats, and I need to find a way for my auto saving script to put inside this script, in a way it doesnt get deleted.
Everytime I add my auto saving script, the circle part is just removed.
-
What is the issue? Everytime I load the leaderboard stats work completely fine. But, when I add my auto saving data script, the whole leaderboard stat (in the upper right hand) is completely deleted.
-
What solutions have you tried so far? I’ve tried a lot of different techniques, it’s just not working. I have ask multiple friends
LEADERBOARD STATS SCRIPT:
local stats = player:findFirstChild("leaderstats")
if stats ~= nil then
local BuildingBlock = stats:findFirstChild("Spree")
local deaths = stats:findFirstChild("Deaths")
deaths.Value = deaths.Value + 1
BuildingBlock.Value = 0
local killer = getKillerOfHumanoidIfStillInGame(humanoid)
handleKillCount(humanoid, player)
end
end
function onPlayerRespawn(property, player)
if property == "Character" and player.Character ~= nil then
local humanoid = player.Character.Humanoid
local p = player
local h = humanoid
humanoid.Died:connect(function() onHumanoidDied(h, p) end )
end
end
function getKillerOfHumanoidIfStillInGame(humanoid)
local tag = humanoid:findFirstChild("creator")
if tag ~= nil then
local killer = tag.Value
if killer.Parent ~= nil then
return killer
end
end
return nil
end
function handleKillCount(humanoid, player)
local killer = getKillerOfHumanoidIfStillInGame(humanoid)
if killer ~= nil then
local stats = killer:findFirstChild("leaderstats")
if stats ~= nil then
local kills = stats:findFirstChild("Kills")
local cash = stats:findFirstChild("Cash")
local BuildingBlock = stats:findFirstChild("Spree")
--------------------------------------------------------------------
if killer ~= player then
kills.Value = kills.Value + 1
cash.Value = cash.Value + 100
BuildingBlock.Value = BuildingBlock.Value + 1
if math.floor(BuildingBlock.Value/increment) == BuildingBlock.Value/increment then
weapons[(BuildingBlock.Value/increment)*2]:clone().Parent = killer.Character
print("mommy says im kool aid :)")
local ese = game.Lighting.KILLSTREK:clone()
ese.Parent = killer.PlayerGui
ese.Frame.TextLabel.Text = weapons[(BuildingBlock.Value/increment)*2 -1 ]
coroutine.resume(coroutine.create(function() wait(5) ks:remove() end))
end
else
kills.Value = kills.Value - 1
end
-------------------------------------------------------------------------------------------------
local data
local success, errormessage = pcall(function()
data = myDataStore:GetAsync(player.UserId.."-Kills")
end)
if success then
kills.Value = data
else
print("Error!")
warn(errormessage)
end
end
end
end
-----------------------------------------------------------------------------
function findAllFlagStands(root)
local c = root:children()
for i=1,#c do
if (c[i].className == "Model" or c[i].className == "Part") then
findAllFlagStands(c[i])
end
if (c[i].className == "FlagStand") then
table.insert(findAllFlagStands, c[i])
end
end
end
function onPlayerEntered(newPlayer)
local stats = Instance.new("IntValue")
stats.Name = "leaderstats"
local kills = Instance.new("IntValue")
kills.Name = "Kills"
kills.Value = 0
local cash = Instance.new("IntValue")
cash.Name = "Cash"
cash.Value = 0
local BuildingBlock = Instance.new("IntValue")
BuildingBlock.Name = "Spree"
BuildingBlock.Value = 0
local deaths = Instance.new("IntValue")
deaths.Name = "Deaths"
deaths.Value = 0
cash.Parent = stats
kills.Parent = stats
deaths.Parent = stats
BuildingBlock.Parent = stats
while true do
if newPlayer.Character ~= nil then break end
wait(5)
end
local humanoid = newPlayer.Character.Humanoid
humanoid.Died:connect(function() onHumanoidDied(humanoid, newPlayer) end )
newPlayer.Changed:connect(function(property) onPlayerRespawn(property, newPlayer) end )
stats.Parent = newPlayer
end
game.Players.ChildAdded:connect(onPlayerEntered)```
***AUTO SAVE SCRIPT:***
```local DataStoreService = game:GetService("DataStoreService")
local myDataStore = DataStoreService:GetDataStore("myDataStore")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local Kills = Instance.new("IntValue")
Kills.Name = "Kills"
Kills.Parent = leaderstats
------------------------------------------------------ Get Data
local data
local success, errormessage = pcall(function()
data = myDataStore:GetAsync(player.UserId.."-Kills")
end)
if success then
Kills.Value = data
else
print("Error!")
warn(errormessage)
end
end)
---------------------------------------------- Save data
game.Players.PlayerRemoving:Connect (function(player)
local success, errormessage = pcall(function()
myDataStore:SetAsync(player.UserId.."-Kills",player.leaderstats.Kills.Value)
end)
if success then
print("Data successfully saved!")
else
print("Error!")
warn(errormessage)
end
end)```