The error in the bottom corner is my issue, It’s not a valid member of the folder but it clearly is there under my player, The script below is the folder, I am trying to get both stats on this UI. I have no idea on how to fix this after searching up solutions, any Ideas?
local DataStore = game:GetService("DataStoreService")
--spills
local ds = DataStore:GetDataStore("PlayTime")
local dsb = DataStore:GetDataStore("SpillCollection")
game.Players.PlayerAdded:connect(function(player)
local leader = Instance.new("Folder",player)
leader.Name = "Stats"
--spills
local Time = Instance.new("IntValue",leader)
Time.Name = "TimePlayed"
Time.Value = ds:GetAsync(player.UserId) or 0
ds:SetAsync(player.UserId, Time.Value)
local canSave = true
Time.Changed:connect(function()
if canSave == true then
canSave = false
wait(5)
ds:SetAsync(player.UserId, Time.Value)
canSave = true
end
local WorkerPointt = Time.Value
end)
--spills
local Spill = Instance.new("IntValue",leader)
Spill.Name = "SpillsCleaned"
Spill.Value = dsb:GetAsync(player.UserId) or 0
dsb:SetAsync(player.UserId, Spill.Value)
local canSave = true
Spill.Changed:connect(function()
if canSave == true then
canSave = false
wait(5)
dsb:SetAsync(player.UserId, Spill.Value)
canSave = true
end
local WorkerPointtt = Spill.Value
end)
end)
game.Players.PlayerRemoving:connect(function(player)
--spills
ds:SetAsync(player.UserId, player.Stats.TimePlayed.Value)
dsb:SetAsync(player.UserId, player.Stats.SpillsCleaned.Value)
end)
This code works with leaderstats, as it is fine in my main game.