I am having issues with my function breaking, I need a way to detect if it is or isn’t running, I tried making a variable like isRunning but it didn’t work when the script did break, it breaks under extreme lag and I am trying to get it to be called again if it breaks
I have something called isLoading and if it’s false the player doesn’t become the model/creature until they do load so they don’t lose data, until the script finishes isLoading is false and while it’s false it has a wait, I want to also add a thing that if the function isn’t running anymore it calls it again, sorry if this doesn’t make much sense!
local function GiveData(Player, Morph)
givingData = true
local Data = DatastoreModule.Read(Player)
local StatsFolder = Morph.Humanoid.StatsFolder
local Stats = require(Morph.Humanoid.Stats)
local PlayerCreature = Data.Creatures[Stats.Creature]
if PlayerCreature.GrowthStage ~= Stats.GrowthStage then
checkLoad.loaded = false
if PlayerCreature.GrowthStage == "Adult" and Stats.GrowthStage == "Juvenile" or Stats.GrowthStage == "Child" then
local NewData = {Location = Vector3.new(PlayerCreature.Position.X, PlayerCreature.Position.Y, PlayerCreature.Position.Z), FromData = true}
DoGrowth(Player, Morph, NewData)
end
if PlayerCreature.GrowthStage == "Juvenile" and Stats.GrowthStage == "Child" then
local NewData = {Location = Vector3.new(PlayerCreature.Position.X, PlayerCreature.Position.Y, PlayerCreature.Position.Z), FromData = true}
DoGrowth(Player, Morph, NewData)
end
end
StatsFolder.Day.Value = PlayerCreature.Days
if StatsFolder.Day.Value < 1 then
StatsFolder.Day.Value = 1
end
StatsFolder.Parent.Health = PlayerCreature.Health
StatsFolder.Hunger.Value = PlayerCreature.Hunger
if StatsFolder:FindFirstChild("Oxygen") then
StatsFolder.Oxygen.Value = PlayerCreature.Oxygen
end
StatsFolder.Stamina.Value = PlayerCreature.Stamina
StatsFolder.Thirst.Value = PlayerCreature.Thirst
if PlayerCreature.GrowthStage == Stats.GrowthStage then
StatsFolder.Growth.Value = PlayerCreature.Growth
checkLoad.loaded = true
end
givingData = false
end