So, I am making a “Eating Simulator” because I thought it would be fun and I’m trying to use DataStore2 but it is telling me:
Data store food was not saved as it was not updated.
I am new to data store so I don’t know what is wrong… (Yes I do know I am using a remote event to increment the players data and this is not safe I will change that later.)
local plrStats = game:GetService("ServerStorage"):WaitForChild("PlrStats")
local DSS = game:GetService("DataStoreService")
local ds1 = DSS:GetDataStore("FoodSave")
local debris = game:GetService("Debris")
local DataStore2 = require(game:GetService("ServerStorage"):WaitForChild("MainModule"))
local defaultFood = 0
local tipTemp = script:WaitForChild("Tip")
function createTip(plr, text)
if plr:IsA("Player") and plr:FindFirstChild("PlayerGui") then
pcall(function()
local new = tipTemp:Clone()
new.Parent = plr:FindFirstChild("PlayerGui")
new:FindFirstChild("TextLabel").Text = "Congrats, " .. plr.Name .. " on reaching " .. tostring(text) .. " food!!!"
debris:AddItem(new, 5)
end)
end
end
game:GetService("Players").PlayerAdded:Connect(function(plr)
if plrStats:FindFirstChild(plr.Name) then plrStats:FindFirstChild(plr.Name):Destroy() end
local foodDataStore = DataStore2("food", plr)
local stats = Instance.new("Folder")
stats.Name = plr.Name
stats.Parent = plrStats
wait()
local rFood = Instance.new("IntValue")
rFood.Name = "rFood"
rFood.Parent = stats
wait()
local ID = Instance.new("IntValue")
ID.Name = "UserId"
ID.Value = plr.UserId
ID.Parent = stats
wait()
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = plr
wait()
local food = Instance.new("IntValue")
food.Name = "Food"
food.Parent = leaderstats
food.Changed:Connect(function()
if food.Value == 100 then
createTip(plr, 100)
end
end)
local function foodUpdate(updatedValue)
food.Value = foodDataStore:Get(updatedValue)
end
foodUpdate(defaultFood)
foodDataStore:OnUpdate(foodUpdate)
spawn(function()
while wait() do
food.Value = (rFood.Value)
end
end)
end)
local event = game:GetService("ServerStorage"):WaitForChild("AwardStats")
--local cEvent = game:GetService("ReplicatedStorage"):WaitForChild("cAwardStats")
event.OnServerEvent:Connect(function(plr, stat, value)
pcall(function()
if plr:IsA("Player") then
local plrStat = game:GetService("ServerStorage"):FindFirstChild("PlrStats"):FindFirstChild(plr.Name):FindFirstChild(tostring(stat))
local foodDataStore = DataStore2("food", plr)
foodDataStore:Increment(value * 10, defaultFood)
end
end)
end)
So I probably am being dumb but I’m tired so oh well… XD
EDIT: Yes I do have a value in studio set to true called “SaveInStudio”