local DataStoreService = game:GetService("DataStoreService")
local myDataStore = DataStoreService:GetDataStore("myDataStore")
local debounce = false
game.Players.PlayerAdded:Connect(function(player)
local stats = Instance.new("StringValue", player)
stats.Name = "leaderstats"
stats.Parent = player
local Wins = Instance.new("IntValue")
Wins.Name = "Wins"
Wins.Value = 0
Wins.Parent = stats
local playerUserId = "Player_"..player.UserId
myDataStore:GetAsync(playerUserId)
-- LOAD DATA
local data
local success, errormessages = pcall(function()
local data = myDataStore:GetAsync(playerUserId)
end)
if success then
Wins.Value = data
-- Set our Data
end
game.Players.PlayerRemoving:Connect(function(player)
local playerUserId = "Player_"..player.UserId
local data = player.leaderstats.Wins.Value
local success, errormessages = pcall(function()
myDataStore:SetAsync(playerUserId, data)
end)
if success then
print("Data Succesfully saved")
else
print("There was an error when saving Data")
warn(errormessages)
end
end)
workspace.WinPart.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
if hit.Parent.Humanoid.Health > 0 then
if debounce == false then
debounce = true
-- PLAYER TELEPORTS/Wins
Wins.Value = Wins.Value + 1
hit.Parent.HumanoidRootPart.CFrame = CFrame.new(234, 45.906, -114)
end
else
print("You Lose")
end
wait(1)
debounce = false
end
end)
end)
Basically, I want when i Touch a brick, the stats to be saved, but it's not working

1 comment
I got another trick that works