All you have to do is put a BindableEvent "JailEvent" in ServerStorage and this should work
dss = game:GetService("DataStoreService")
jailData = dss:GetDataStore("Jail")
jailTimes = {}
function jail(player,t)
if player and t and not jailTimes[player] then
jailTimes[player] = {t,tick()}
local char = player.Character or player.CharacterAdded:wait()
wait(1)
print(player.Name .. " jailed for " .. t .. " seconds")
char:MoveTo(workspace.Jail.Jail.Position)
wait(t)
jailTimes[player] = nil
if player.Parent==game.Players then
print(player.Name .. " completed his sentence")
char:MoveTo(workspace.Jail.Unjail.Position)
jailData:SetAsync(tostring(player.UserId),0)
end
end
end
game.Players.PlayerRemoving:connect(function(player)
local times = jailTimes[player]
if times then
local remaining = math.floor( times[1] - (tick() - times[2]) )
print(player.Name .. " left the game during jail. " .. remaining .. " seconds remain.")
jailData:SetAsync(tostring(player.UserId),remaining)
end
end)
game.Players.PlayerAdded:connect(function(player)
local jailTime = jailData:GetAsync(tostring(player.UserId)) or 0
if jailTime > 0 then
jail(player,jailTime)
end
end)
game.ServerStorage:WaitForChild('JailEvent').Event:connect(function(player,t)
jail(player,t)
end)
Tool
tool = script.Parent
db = false
function touch(hit)
if db then return end
db=true
local char = hit.Parent
local hum = char:FindFirstChild('Humanoid')
if hum then
local player = game.Players:GetPlayerFromCharacter(char)
if player then
game.ServerStorage.JailEvent:Fire(player,30)
wait(3)
end
end
db=false
end
function sel()
tool.Handle.Touched:connect(touch)
end
tool.Equipped:connect(sel)
3 comments
Friend me on ROBLOX..
You can
make it so they always start off in the jail