Why is this not Saving or Loading?
So, this script is supposed to Save and Load the time spent in-game by the people above or that rank in the group, but it prints this error after it has counted 1 minute, can anyone help me understand why it thinks it is missing or nil?
-- Argument 2 missing or nil
-- Script 'ServerScriptService.StaffTime.StaffTimeCounter', line 74 - global TimeCount
-- Script 'ServerScriptService.StaffTime.StaffTimeCounter', line 94
-- Stack end
The script is:
002 | local DataStore = game:GetService( 'DataStoreService' ):GetDataStore( 'StaffTime' ); |
004 | local SP = script.Parent; |
006 | local Users = SP:WaitForChild( 'Users' ); |
007 | local Default = Users:WaitForChild( 'Default' ); |
009 | local Settings = require(SP:WaitForChild( 'Settings' )); |
010 | local GroupId = Settings.GroupId; |
011 | local StaffRank = Settings.StaffRank; |
012 | local ViewerRank = Settings.ViewerRank; |
015 | function CreatePlayerTime(Player) |
016 | local PlayerTime = Default:Clone() |
017 | PlayerTime.Name = Player.Name |
018 | PlayerTime.Parent = Users |
019 | local TimeInstances = { |
020 | Days = PlayerTime:WaitForChild( 'Days' ); |
021 | Hours = PlayerTime:WaitForChild( 'Hours' ); |
022 | Minutes = PlayerTime:WaitForChild( 'Minutes' ); |
023 | Seconds = PlayerTime:WaitForChild( 'Seconds' ) |
028 | function SaveTime(Player, PlayerTime, OldValue) |
029 | local SaveEnsure = pcall ( function () |
030 | if ( type (PlayerTime) = = ( 'table' )) then |
031 | local PlayerTimeValues = { |
032 | Days = PlayerTime.Days.Value; |
033 | Hours = PlayerTime.Hours.Value; |
034 | Minutes = PlayerTime.Minutes.Value; |
035 | Seconds = PlayerTime.Seconds.Value; |
037 | return PlayerTimeValues |
040 | if ( not SaveEnsure) then |
045 | function LoadTime(Player, PlayerTime) |
046 | local LoadEnsure = pcall ( function () |
047 | if ( type (PlayerTime) = = ( 'table' )) then |
048 | local Key = 'Id_' ..Player.userId |
049 | if (DataStore:GetAsync(Key)) then |
050 | PlayerTime.Days.Value = DataStore:GetAsync(Key).Days |
051 | PlayerTime.Hours.Value = DataStore:GetAsync(Key).Hours |
052 | PlayerTime.Minutes.Value = DataStore:GetAsync(Key).Minutes |
053 | PlayerTime.Seconds.Value = DataStore:GetAsync(Key).Seconds |
054 | elseif ( not DataStore:GetAsync(Key)) then |
059 | if ( not LoadEnsure) then |
064 | function TimeCount(Player, PlayerTime) |
065 | if ( type (PlayerTime) = = ( 'table' )) then |
066 | local Key = 'Id_' ..Player.userId |
068 | if (PlayerTime.Seconds.Value < 59 ) then |
069 | PlayerTime.Seconds.Value = PlayerTime.Seconds.Value + 1 |
070 | elseif (PlayerTime.Seconds.Value > = 59 ) then |
071 | PlayerTime.Seconds.Value = 0 |
072 | if (PlayerTime.Minutes.Value < 59 ) then |
073 | PlayerTime.Minutes.Value = PlayerTime.Minutes.Value + 1 |
074 | DataStore:UpdateAsync(Key, SaveTime(Player, PlayerTime)) |
075 | elseif (PlayerTime.Minutes.Value > = 59 ) then |
076 | PlayerTime.Minutes.Value = 0 |
077 | if (PlayerTime.Hours.Value < 23 ) then |
078 | PlayerTime.Hours.Value = PlayerTime.Hours.Value + 1 |
079 | elseif (PlayerTime.Hours.Value > = 23 ) then |
080 | PlayerTime.Hours.Value = 0 |
081 | PlayerTime.Days.Value = PlayerTime.Days.Value + 1 |
090 | game.Players.PlayerAdded:connect( function (Player) |
091 | if (Player:GetRankInGroup(GroupId) > = StaffRank) then |
092 | local PlayerTime = CreatePlayerTime(Player) |
093 | LoadTime(Player, PlayerTime) |
094 | TimeCount(Player, PlayerTime) |
098 | game.Players.PlayerRemoving:connect( function (Player) |
099 | local PlayerTime = Users:FindFirstChild(Player.Name) |