Hello! So I was making a game with a friend and then this happened
Idk how it happened but are data wasn’t saving.
Heres the stats script
local dataStores = game:GetService("DataStoreService"):GetDataStore("TixDataStore")
local defaultTix = 0
local playersLeft = 0
game.Players.PlayerAdded:Connect(function(player)
playersLeft = playersLeft + 1
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local Tix = Instance.new("IntValue")
Tix.Name = "Tix"
Tix.Value = 0
Tix.Parent = leaderstats
local Wins = Instance.new("IntValue")
Wins.Name = "Wins"
Wins.Value = 0
Wins.Parent = leaderstats
player.CharacterAdded:Connect(function(character)
character.Humanoid.Died:Connect(function()
-- Whenever sombody dies, this event will run
if character:FindFirstChild("GameTag") then
character.GameTag:Destroy()
end
player:LoadCharacter()
end)
end)
-- Data Stores
local player_data
pcall(function()
player_data = dataStores:GetAsync(player.UserId.."-Tix") -- 000000-Tix
player_data = dataStores:GetAsync(player.UserId.."-Wins") -- 000000-Wins
end)
if player_data ~= nil then
-- Player has ssaved data, load it in
Tix.Value = player_data
else
-- New Player
Tix.Value = defaultTix
end
end)
local bindableEvent = Instance.new("BindableEvent")
game.Players.PlayerRemoving:Connect(function(player)
pcall(function()
dataStores:SetAsync(player.UserId.."-Tix",player.leaderstats.Tix.Value)
dataStores:SetAsync(player.UserId.."-Wins",player.leaderstats.Wins.Value)
print("Players Data Has Succsessfully Saved!")
playersLeft = playersLeft - 1
bindableEvent:Fire()
end)
end)
game:BindToClose(function()
-- This will be triggered upon shutdown
while playersLeft > 0 do
bindableEvent.Event:Wait()
end
end)