Hey, I'm currently working on a game, trying to make datastore's, but it doesnt work. This wont be about fixing datastores, because there is this one issue, where it basically cannot use FindFirstChild OR WaitForChild. Really annoying. Does anyone have a fix for this?
Leaderstats Module:
local Leaderstats = {}
-- Services
local RunService = game:GetService("RunService")
local DataStore = game:GetService("DataStoreService")
local DataStoreKey = DataStore:GetDataStore("DataStore_6")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local GameCore = require(ReplicatedStorage:WaitForChild("GameCore"))
-- Misc
local LeaderStats = script:WaitForChild("leaderstats")
local Playerstats = script:WaitForChild("PlayerStats")
-- Functions
function Leaderstats.new(Player)
local LsClone = LeaderStats:Clone()
local PsClone = Playerstats:Clone()
LsClone.Parent = Player
PsClone.Parent = Player
end
function Leaderstats:LoadDataStore(Player)
local Leaderstats = Player:FindFirstChild("leaderstats")
local Money = Leaderstats:FindFirstChild("Money")
local MoneyData
local Success, Errormessage = pcall(function()
warn("[!] Loading "..Player.Name.."'s data...")
MoneyData = DataStoreKey:GetAsync(Player.UserId.." | money", Player.Leaderstats)
end)
if Success then
warn("[!] Successfully loaded "..Player.Name.."'s data!")
else
warn("[!] Fatal Loading error: "..Errormessage)
end
end
function Leaderstats:SaveDataStore(Player)
local Leaderstats = Player:FindFirstChild("leaderstats")
local Money = Leaderstats:FindFirstChild("Money")
local success, errormessage = pcall(function()
warn("[!] Saving "..Player.Name.."'s data...")
DataStoreKey:SetAsync(Player.UserId.." | money", Player.Leaderstats)
end)
if success then
warn("[!] Sucessfully saved "..Player.Name.."'s data!")
else
warn("[!] Fatal Saving error: "..errormessage)
end
end
return Leaderstats
MainScript (script requiring the leaderstats module):
-- Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")
local TweenService = game:GetService("TweenService")
local Lightning = game:GetService("Lighting")
local RunService = game:GetService("TweenService")
local Players = game:GetService("Players")
-- Modules
local Bank = require(script.Bank)
local Leaderstats = require(script.Leaderstats)
local GameCore = require(ReplicatedStorage:WaitForChild("GameCore"))
-- Misc
local Sounds = ReplicatedStorage:WaitForChild("Sounds")
-- Functions
-- Code
Players.PlayerAdded:Connect(Leaderstats.new)
Players.PlayerAdded:Connect(Leaderstats.LoadDataStore)
Players.PlayerRemoving:Connect(Leaderstats.SaveDataStore)
Lightning.ClockTime = GameCore.StartTime
-- Spawn / While Loops
spawn(function() -- Day Light Loop
print("Day Light Loop Started")
while wait(1) do
GameCore:Tween(1, "Sine", "Out", {ClockTime = Lightning.ClockTime + 1/45}, Lightning):Play()
if math.floor(Lightning.ClockTime) == 6 then
GameCore:Tween(1, "Sine", "Out", {Volume = 0.5}, Sounds:WaitForChild("DayAmbient")):Play()
GameCore:Tween(1, "Sine", "Out", {Volume = 0}, Sounds:WaitForChild("NightAmbient")):Play()
end
if math.floor(Lightning.ClockTime) == 18 then
GameCore:Tween(1, "Sine", "Out", {Volume = 0}, Sounds:WaitForChild("DayAmbient")):Play()
GameCore:Tween(1, "Sine", "Out", {Volume = 0.5}, Sounds:WaitForChild("NightAmbient")):Play()
end
end
end)
spawn(function() -- Bank Loop
print("Bank Loop Started")
repeat wait() until math.floor(Lightning.ClockTime) == 11
Bank:Open()
print("Bank Opend")
while wait(Bank.TimeToRob + 60) do
Bank:Open()
print("Bank Opend")
end
end)
Help would seriously be helpful, I really don't know what to do. Thanks!

2 comments
which line is erroring?
It would be much easier if you told us which line had the error