I researched this huge topic a lot and I still couldn’t find the solution.
Using the current Studio version 440.
In my case, the error “Not running script because past shutdown deadline” occurs only while debugging, when I stop the game (which triggers DataStore2 to write the cache, I think).
I get the same message 8x.
This does not occur in the normal execution of the game (when there are no breakpoints).
How to solve this?
If i use Get() and Set() every 0.1 sec does it cause problems cause I’ve had my data reverted a couple times when i was testing. Am i doing something wrong with my script or something else. I am currently using the latest version from the github releases v1.3.1.
Code:
local OldStamina = PlayerStamina.Value
PlayerStamina.Changed:Connect(function(NewStamina)
local char = plr.Character or plr.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
if NewStamina > OldStamina and PlayerStamina.Value < PlayerStamina.MaxValue and not char:FindFirstChild("ForceField") then
OldStamina = NewStamina
local Stats = D2("Stats",plr):Get()
Stats.Stamina += 1/250
Stats.Hunger = math.clamp(Stats.Hunger - 1/350,0,100)
D2("Stats",plr):Set(Stats)
else
OldStamina = NewStamina
end
wait()
end)
while true do
wait(0.1)
local char = plr.Character or plr.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
if not plr:FindFirstChild("StopStaminaRegen") and PlayerStamina.Value < PlayerStamina.MaxValue and Hunger.Value > 0 then
local Multiplier = 1
if plr:FindFirstChild("EnergyBoost") then
Multiplier = 2
end
PlayerStamina.Value += (PlayerStamina.MaxValue/150) * Multiplier
end
end
How would I use this with soft shutdown? Whenever I attempt to saveall then do the tp, the player just disappears but never gets teleported so its just a regular shutdown
Edit: apparently there is a bind to close function in the module but never found it in the api
Edit2: apparently saveall changes the player ancestry which when i commented allowed me to actually tp properly
Only the Coins part work for some reason Code1 doesn’t save. Also is it possible to save Bools in a leaderstats type thing?
local Players = game:GetService(“Players”)
local ServerScriptService = game:GetService(“ServerScriptService”)
local Workspace = game:GetService(“Workspace”)
local DataStore2 = require(ServerScriptService.DataStore2)
DataStore2.Combine(“DATA”, “Coins”)
DataStore2.Combine(“DATA”, “Code1”)
Players.PlayerAdded:Connect(function(player)
local CoinsStore = DataStore2(“Coins”, player)
local Code1Store = DataStore2(“Code1”, player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
local TwitterCodes = Instance.new("Folder")
TwitterCodes.Name = "TwitterCodes"
local Code1 = Instance.new("NumberValue")
Code1.Name = "Code1"
Code1.Value = Code1Store:Get(0)
Code1.Parent = leaderstats
local Coins = Instance.new("NumberValue")
Coins.Name = "Coins"
Coins.Value = CoinsStore:Get(0) -- Amount they will have by default
Coins.Parent = leaderstats
CoinsStore:OnUpdate(function(NewCoins) -- This function runs every time the datastore changes
Coins.Value = NewCoins
end)
Code1Store:OnUpdate(function(NewCode1)
Code1.Value = NewCode1
end)
leaderstats.Parent = player
TwitterCodes.Parent = player
Hey, I’m currently willing to use this method and it works super fine + now that I understood how it works, I can work pretty fast with it. I have just one question: to look into players’ data, I use a plugin named DataStoreEditor (DataStore Editor - Roblox), BUT with DSS2 I don’t get what’s the actual key to find this data. I tried using the key put after DSS("Data",player) (Data is the key) but it doesn’t seem to be finding any data. Might be a really dumb question, but since I started using it a couple days ago, I’m not sure on how to find players’ data, or even if it’s possible. So, how can I find the data, possibly with that plugin?
This amazing module has saved me so much time and effort with saving data, and the fact that it is so easy to use and how it just works makes it even better.
I feel like I’m writing a review or something, but I just had to express how awesome DataStore2 is…
Thank you so much for this!
I found myself unable to save data or load data from offline players because of that, also I dont quite understand why you made it so you have to use a player instance in the first place rather than just the ID of the player?
The Touched event does not return the player that touched it, it returns the part that touched it.
To get the player, you should use game.Players:GetPlayerFromCharacter(character)
game.Workspace.Path2.Touched:Connect(function(hit) -- hit is the part that touched it
local player = game.Players:GetPlayerFromCharacter(hit.Parent) -- it can return nil if hit.Parent isn't a player's character.
if player then -- checking if it's a valid player
local TokenData = DataStore2("Tokens", player)
TokenData:Increment(10)
print("Tokens increased by 10!")
wait(10)
end
end)
Also assuming you’re using wait(10) to make sure the event doesn’t fire too much, events don’t yield.
If you’re using wait(10) to stop the event from firing too much, use debounces instead.
The link to how to use debounces is here.
game.Workspace.Path2.Touched:connect(function(Hit)
local Player = game.Players:GetPlayerFromCharacter(Hit.Parent)
if not Player then return end
--Write your code here
end)