function CountTime(plr, Time)
print("start count")
local jail = true
local timeToFree = tick() + Time -- jail time in seconds
local saveTime = timeToFree - tick()
game.Players.PlayerRemoving:Connect(function(plrRemoved)
saveTime(plrRemoved,saveTime) -- error is here
print("saved time")
end)
while jail do
print(timeToFree)
wait(1)
if tick() > timeToFree then
print("unjailed")
JailModule.Unjail(plr)
jail = false
end
end
end
When it goes to the saveTime() in the Count Time function, it gives me an error:
Also, now I have a problem with DataStore. It saves the time normal as far as I see, but the DataStore doesnât detect the player when he joins the game.
That is how I save the Time and UserId in DataStore:
local info = {plr.UserId; Time}
JailDS:SetAsync(info, true)
And when the player joins:
local jailed
local success, errormsg = pcall(function()
jailed = JailDS:GetAsync(plrUserId)
end)
But the problem is, it just doesnât detect anything, doesnât write anything in the output. I guess its the problem in the DataStore, in the
local info = {plr.UserId; Time}
But I donât know how to fix it, nor how to write it the other way.
Youâre trying to set the DataStore key as the player data:
local UserId = tostring(Player.UserId)
local success, result = pcall(function()
return JailDS:GetAsync(UserId)
end)
print(result)
-- to overwrite the jail data
JailDS:SetAsync(UserId, Time)
function CountTime(plr, Time)
print("start count")
local jail = true
local timeToFree = tick() + Time -- ERROR HERE LINE 87
Line 77:
if jailed then
for _,part in pairs(JailSpawns:GetChildren()) do
table.insert(JailSpawnsTBL, part.CFrame)
end
wait(1)
CountTime(plr, TimeToJail) -- ERROR HERE LINE 77
plr.Character:SetPrimaryPartCFrame(JailSpawnsTBL[math.random(#JailSpawnsTBL)])
char.Jailed.Value = true
end
TimeToJail is a variable, that is nil by default:
local TimeToJail
But in a function, it makes it equal to Time variable.
function JailModule.Jail(plr, Time, reason)
local UserId = tostring(plr.UserId)
local info = {UserId; Time}
TimeToJail = Time -- TIME TO JAIL VARIABLE