I’ve been coding a simulator with the popular datastore module “Datastore2”
I also have problems with messy code and I would love to see the code that is actually needed!
-------------------
----- SERVICES ----
-------------------
local ReplicatedStorage = game:GetService("ReplicatedStorage")
-------------------
----- VARIABLES ---
-------------------
local Modules = ReplicatedStorage:FindFirstChild("Modules")
local DataStore2 = require(Modules:FindFirstChild("DataStore2"))
-------------------
----- FUNCTIONS ---
-------------------
game.Players.PlayerAdded:Connect(function(Player)
local DataStore_Speed = DataStore2("Speed", Player)
local DataStore_Rebirth = DataStore2("Rebirth", Player)
local Board = Instance.new("Folder")
Board.Name = "Board"
Board.Parent = Player
local Speed = Instance.new("IntValue")
Speed.Name = "Speed"
Speed.Parent = Board
local Rebirth = Instance.new("IntValue")
Rebirth.Name = "Rebirth"
Rebirth.Value = 0
Rebirth.Parent = Board
local function OnSpeedUpdate(UpdatedValue)
Speed.Value = DataStore_Speed:Get(UpdatedValue)
end
local function OnRebirthUpdate(UpdatedValue)
Rebirth.Value = DataStore_Rebirth:Get(UpdatedValue)
end
OnSpeedUpdate(0)
OnRebirthUpdate(0)
DataStore_Speed:OnUpdate(OnSpeedUpdate)
DataStore_Rebirth:OnUpdate(OnRebirthUpdate)
end)