The entire reason for my question is to see if he even did it right.
I believe the datastore was cut off and the code snippet wasn’t the whole thing, but you could be completely right here. Seems weird it wasn’t included.
local TimeStore = game:GetService("DataStoreService"):GetDataStore("MinutesPlayed")
full code here
~~lua
local DataStoreService = game:GetService(“DataStoreService”)
local DataStore = DataStoreService:GetDataStore(“TimeStats”)
game.Players.PlayerAdded:Connect(function(Player)
local Leaderstats = Instance.new(“Folder”)
Leaderstats.Name = “leaderstats”
Leaderstats.Parent = Player
local Time = Instance.new(“IntValue”)
Time.Name = “Time”
Time.Value = 0
Time.Parent = Leaderstats
local Data = DataStore:GetAsync(Player.UserId)
if Data then
Time.Value = Data
end
coroutine.resume(coroutine.create(function()
while true do
wait(60)
Time.Value = Time.Value + 1
end
end))
end)
game.Players.PlayerRemoving:Connect(function(Player)
DataStore:SetAsync(Player.UserId, Player.leaderstats.Time.Value)
end)
game:BindToClose(function()
for i, Player in pairs(game.Players:GetPlayers()) do
DataStore:SetAsync(Player.UserId, Player.leaderstats.Time.Value)
end
end)
~~
idk why that posted weird but there i tried changing all values straight from minutes over to time
try adding a print line inside player removing then test it
You posted ‘~’ instead of ‘`’. You just held shift down, no worries.
I think this should work fine. Again, why is the coroutine even necessary though?
the coroutine just felt simplier to put in (i understood its use a little more)
You’re using phone quotation marks(“”) instead of computer ones(""). rlua does not work with phone quotation marks.
Here is it with normal quotation marks that will work with rlua:
local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("TimeStats")
game.Players.PlayerAdded:Connect(function(Player)
local Leaderstats = Instance.new("Folder")
Leaderstats.Name = "leaderstats"
Leaderstats.Parent = Player
local Time = Instance.new("IntValue")
Time.Name = "Time"
Time.Value = 0
Time.Parent = Leaderstats
local Data = DataStore:GetAsync(Player.UserId)
if Data then
Time.Value = Data
end
coroutine.resume(coroutine.create(function()
while true do
wait(60)
Time.Value = Time.Value + 1
end
end))
end)
game.Players.PlayerRemoving:Connect(function(Player)
DataStore:SetAsync(Player.UserId, Player.leaderstats.Time.Value)
end)
game:BindToClose(function()
for i, Player in pairs(game.Players:GetPlayers()) do
DataStore:SetAsync(Player.UserId, Player.leaderstats.Time.Value)
end
end)
the coroutine isnt the problem though the time works perfectly it just doesnt save to it the datastore aka TimeStats
Instead of having local Data = DataStore:GetAsync(Player.UserId) when loading do local Data = DataStore:GetAsync(Player.UserId, Player.leaderstats.Time.Value) (maybe)
doesnt work good shout though appreciate it
what comes up when you print(data) on loading
What is rlua?
Install a different keyboard and try again. I believe Swype doesn’t do this.
Does it save when there’s multiple players in a server, and only one leaves?
yes it doesnt save when its one player in server and it shuts down as far as i know when multiple players are in server and one leaves and rejoins it does save
rlua stands for Roblox lua
hey i tried using your scripts to test but its still not saving which leads me to believe its something else
When you load the data could you just do print(data) and show me what it says please
i fixed it i had a seperate script from a temp mod menu which was cleaning my datastores everytime game shutdown
Ah, well thats good to know that its all fixed now