Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to keep a player in jail even if the player leaves the game? [Not answered]

Asked by 4 years ago
Edited 4 years ago

I want to keep the player in jail even if the player leaves the game Here is the script for the arrest system

------------------------------------------------------
---------- | ARREST_MAIN | MAX_Y | CODE | ------------
------------------------------------------------------

game.Players.PlayerAdded:connect(function(plr)
    if plr:WaitForDataReady() then
        local v = Instance.new("IntValue")
        v.Name = "Arrested"
        v.Parent = plr
        plr.Arrested.Value = plr:LoadNumber("ArrestedV")

        if plr.Arrested.Value > 0 then
            plr.TeamColor = BrickColor.new("Lapis")
            plr:LoadCharacter()
        end
        plr.ChildAdded:connect(function(c)
            if c.Name == "Arrested1" then
                plr.TeamColor = BrickColor.new("Lapis")
                plr:LoadCharacter()
                if plr.PlayerGui:FindFirstChild("MainFrame") then
                    plr.PlayerGui:FindFirstChild("MainFrame").Control.Visible = false
                end
                for i,v in pairs(plr.Backpack:GetChildren()) do
                    if v:IsA("Tool") or v:IsA("HopperBin") then
                        v:Destroy()
                    end
                end
            end
        end)
    end
end)


while true do 
    wait(1)
    for i,v in pairs(game.Players:GetChildren()) do
        if v.TeamColor == BrickColor.new("Lapis") then
            v.Arrested.Value = v.Arrested.Value - 1
            v:SaveNumber("ArrestedV", v.Arrested.Value)
            if v.Arrested.Value < 0 then

                v:SaveNumber("ArrestedV", v.Arrested.Value)
                v.TeamColor = BrickColor.new("Maroon")

                v:LoadCharacter()
            end
        end
    end
end

------------------------------------------------------
---------------------- | END | -----------------------
------------------------------------------------------

I tried making a datastore but that didn't work Here is the datastore script

local DataStoreService = game:GetService("DataStoreService")
local Arreststore = DataStoreService:GetDataStore("Arrestsaving")

game.Players.PlayerAdded:Connect(function(player)
    pcall (function()
        local Arrested = Instance.new("IntValue",player)
        Arrested.Name = "Arrested"
        Arrested.Value = Arreststore:GetAsync(player.UserId) or 0
        Arrested.Changed:Connect(function()
            Arreststore:SetAsync(player.UserId,player.Arrested.Value)
            print("Time saved")
        end)
    end)
end)

game.Players.PlayerRemoving:Connect(function(player)
    pcall (function()
    Arreststore:SetAsync(player.UserId,player.Arrested.Value)
    print("Time saved")
end)

1 answer

Log in to vote
0
Answered by 4 years ago

datastores will solve you problem. https://developer.roblox.com/en-us/articles/Data-store datastores basically save data so you can just save a boolean value and check if its true to see if hte player is in prison or something idk

0
I tried to make a datastore script but it didn't work WiryIndriunas 0 — 4y
Ad

Answer this question