You can write your topic however you want, but you need to answer these questions:
- What do you want to achieve? Keep it simple and clear!
I am attempting to make my datastore save values but it is not.
- What is the issue? Include screenshots / videos if possible!
It does not save with no errors printed out.
here is my code
local MainStore = game:GetService("DataStoreService"):GetDataStore("MainStore")
local HttpService = game:GetService("HttpService")
local function SavePlayerData(player)
local success, err = pcall(function()
local data = {
Clicks = player:WaitForChild("leaderstats").Clicks.Value;
Gems = player:WaitForChild("leaderstats").Gems.Value;
Rebirths = player:WaitForChild("leaderstats").Rebirths.Value;
WalkSpeed = player:WaitForChild("HiddenStats").WalkSpeed.Value;
TotalGems = player:WaitForChild("TotalGems").Value;
TotalEggs = player:WaitForChild("TotalEggs").Value;
TotalClicks = player:WaitForChild("TotalClicks").Value;
TimePlayed = player:WaitForChild("TimePlayed").Value;
MagmaPortal = player:WaitForChild("MagmaPortal").Value;
OceanPortal = player:WaitForChild("OceanPortal").Value;
OasisPortal = player:WaitForChild("OasisPortal").Value;
}
MainStore:SetAsync("TestPlayer-"..player.UserId, data)
end)
if success then
print("saved data")
else
print(err)
end
end
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
local data
local success,err = pcall(function()
data = MainStore:GetAsync("TestPlayer-"..player.UserId)
end)
if success then
print("loaded player data")
else
print(err)
end
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local HiddenStats = Instance.new("Folder")
HiddenStats.Name = "HiddenStats"
HiddenStats.Parent = player
local coins = Instance.new("IntValue")
coins.Name = "Clicks"
if data then coins.Value = data.Clicks else coins.Value = 0 end
coins.Parent = leaderstats
local DailyRewards = Instance.new("StringValue")
DailyRewards.Name = "DailyRewards"
DailyRewards.Value = HttpService:JSONEncode({nil})
DailyRewards.Parent = HiddenStats
local IsOpening = Instance.new("BoolValue")
IsOpening.Value = false
IsOpening.Parent = player
IsOpening.Name = "IsOpening"
local Island = Instance.new("StringValue")
Island.Name = "Island"
Island.Value = "Grassy"
Island.Parent = player
local Multiplier = Instance.new("IntValue")
Multiplier.Name = "Multiplier"
Multiplier.Value = 1
Multiplier.Parent = player
local gems = Instance.new("NumberValue")
gems.Name = "Gems"
if data then gems.Value = data.Gems else gems.Value = 0 end
gems.Parent = leaderstats
local TotalGems = Instance.new("IntValue")
TotalGems.Name = "TotalGems"
if data then TotalGems.Value = data.TotalGems else TotalGems.Value = 0 end
TotalGems.Parent = player
local TotalEggs = Instance.new("IntValue")
TotalEggs.Name = "EggsOpened"
if data then TotalEggs.Value = data.TotalEggs else TotalEggs.Value = 0 end
TotalEggs.Parent = player
local Rebirths = Instance.new("NumberValue")
Rebirths.Name = "Rebirths"
if data then Rebirths.Value = data.Rebirths else Rebirths.Value = 0 end
Rebirths.Parent = leaderstats
local WalkSpeed = Instance.new("IntValue")
WalkSpeed.Name = "WalkSpeed"
if data then WalkSpeed.Value = data.WalkSpeed else WalkSpeed.Value = 15 end
WalkSpeed.Parent = HiddenStats
char.Humanoid.WalkSpeed = WalkSpeed.Value
WalkSpeed.Changed:Connect(function()
char.Humanoid.WalkSpeed = WalkSpeed.Value
end)
local TotalClicks = Instance.new("IntValue")
TotalClicks.Name = "TotalClicks"
if data then TotalClicks.Value = data.TotalClicks else TotalClicks.Value = 0 end
TotalClicks.Parent = player
local TimePlayed = Instance.new("IntValue")
TimePlayed.Name = "TimePlayed"
if data then TimePlayed.Value = data.TimePlayed else TimePlayed.Value = 0 end
TimePlayed.Parent = player
spawn(function()
while wait(1) do
TimePlayed.Value = TimePlayed.Value + 1
end
end)
local SuperClick = Instance.new("IntValue")
SuperClick.Name = "SuperClick"
SuperClick.Value = 0
SuperClick.Parent = player
local DoubleClick = Instance.new("IntValue")
DoubleClick.Name = "DoubleClick"
DoubleClick.Value = 0
DoubleClick.Parent = player
local SuperClickDB = Instance.new("BoolValue")
SuperClickDB.Name = "SuperClickDB"
SuperClickDB.Value = true
SuperClickDB.Parent = player
local ClickBoost = Instance.new("BoolValue")
ClickBoost.Name = "ClickBoost"
ClickBoost.Value = false
ClickBoost.Parent = player
local GemBoost = Instance.new("BoolValue")
GemBoost.Name = "GemBoost"
GemBoost.Value = false
GemBoost.Parent = player
local MagmaPortal = Instance.new("BoolValue")
MagmaPortal.Name = "MagmaPortal"
MagmaPortal.Parent = player
if data then MagmaPortal.Value = data.MagmaPortal else MagmaPortal.Value = false end
local OceanPortal = Instance.new("BoolValue")
OceanPortal.Name = "OceanPortal"
OceanPortal.Parent = player
if data then OceanPortal.Value = data.OceanPortal else OceanPortal.Value = false end
local OasisPortal = Instance.new("BoolValue")
OasisPortal.Name = "OasisPortal"
OasisPortal.Parent = player
if data then OasisPortal.Value = data.OasisPortal else OasisPortal.Value = false end
end)
end)
game.Players.PlayerRemoving:Connect(function(player)
SavePlayerData(player)
end)
game:BindToClose(function()
if game:GetService("RunService"):IsStudio() == false then
for _,v in pairs(game.Players:GetPlayers()) do
SavePlayerData(v)
wait(1)
end
end
end)