I made a jail system, but the time left to sit is not deducted from the player’s currency.
local Zone = require(game:GetService("ReplicatedStorage").ModuleScripts.Zone)
local replicatedStorage = game:GetService('ReplicatedStorage')
local remotes = replicatedStorage:WaitForChild('Remotes'):WaitForChild("Client")
local container = script.Parent
local zone = Zone.new(container)
zone.playerEntered:Connect(function(player)
local playeradm = player:WaitForChild("Jail"):WaitForChild("Admin").Value
local playerreas = player:WaitForChild("Jail"):WaitForChild("Reason").Value
local timedata = player:WaitForChild("Jail"):WaitForChild("Time").Value
while wait(1) and timedata >= 0 do
timedata -= 1
player.PlayerGui.UI.NotificationsList.Jail.Visible = true
player.PlayerGui.UI.NotificationsList.Jail.Title.Text = "Вы были посажены в тюрьму на "..timedata.." сек. Администратор: "..playeradm..". Причина: "..playerreas
if player:GetAttribute("Jail")==true then
for _, v in pairs(player.Backpack:GetChildren()) do
end
for _, v in pairs(player.Character:GetChildren()) do
if v:IsA("Tool") then
v:Destroy()
local char = player.Character or player.CharacterAdded:Wait()
while wait(1) and timedata <= 0 do
timedata = 0
char:SetPrimaryPartCFrame(game.Workspace.SpawnZone2.CFrame)
player:SetAttribute("Jail", nil)
remotes.CraftBackpack:FireClient(player, false)
playeradm = ""
playerreas = ""
player.PlayerGui.UI.NotificationsList.Visible = false
player.PlayerGui.UI.NotificationsList.Jail.Title.Text = ""
end
end
end
end
end
end)
zone.playerExited:Connect(function(player:Player)
if player and player:GetAttribute("Jail")==true then
local char = player.CharacterAdded:Wait()
for _, v in pairs(player.Backpack:GetChildren()) do
end
for _, v in pairs(player.Character:GetChildren()) do
if v:IsA("Tool") then
end
end
wait(0.1)
char:SetPrimaryPartCFrame(game.Workspace.JailZone.CFrame)
end
end)
Make sure zone.playerEntered:Connect(function(player) really fires.
Also, I’m seeing a few more issues with your script:
The for do function directly after if player:GetAttribute("Jail")==true then does nothing and you’re repeating the same function after that again
You’re setting player.PlayerGui.UI.NotificationsList.Jail.Visible = true over and over again, which isn’t bad, but you should put that line before the while loop
Also, I’m seeing another *while function a little bit later in the script:
while wait(1) and timedata <= 0 do
timedata = 0
char:SetPrimaryPartCFrame(game.Workspace.SpawnZone2.CFrame)
Make sure that doesn’t interfere with the first while function.
Correct me if I didn’t fully understand what you mean, if you have any questions I’ll be happy to help you further
local Zone = require(game:GetService("ReplicatedStorage").ModuleScripts.Zone)
local replicatedStorage = game:GetService('ReplicatedStorage')
local remotes = replicatedStorage:WaitForChild('Remotes'):WaitForChild("Client")
local container = script.Parent
local zone = Zone.new(container)
zone.playerEntered:Connect(function(player)
local playeradm = player:WaitForChild("Jail"):WaitForChild("Admin").Value
local playerreas = player:WaitForChild("Jail"):WaitForChild("Reason").Value
local timedata = player:WaitForChild("Jail"):WaitForChild("Time").Value
if player:GetAttribute("Jail")==true then
while wait(1) and timedata >= 0 do
timedata =- 1
player.PlayerGui.UI.NotificationsList.Jail.Visible = true
player.PlayerGui.UI.NotificationsList.Jail.Title.Text = "Вы были посажены в тюрьму на "..timedata.." сек. Администратор: "..playeradm..". Причина: "..playerreas
for _, v in pairs(player.Backpack:GetChildren()) do
end
for _, v in pairs(player.Character:GetChildren()) do
if v:IsA("Tool") then
v:Destroy()
local char = player.CharacterAdded:Wait()
if timedata <= 0 then
timedata = 0
wait(0.1)
char:SetPrimaryPartCFrame(game.Workspace.SpawnZone2.CFrame)
player:SetAttribute("Jail", nil)
remotes.CraftBackpack:FireClient(player, false)
playeradm = ""
playerreas = ""
player.PlayerGui.UI.NotificationsList.Visible = false
player.PlayerGui.UI.NotificationsList.Jail.Title.Text = ""
end
end
end
end
end
end)
zone.playerExited:Connect(function(player:Player)
if player and player:GetAttribute("Jail")==true then
for _, v in pairs(player.Backpack:GetChildren()) do
end
for _, v in pairs(player.Character:GetChildren()) do
if v:IsA("Tool") then
end
end
local char = player.CharacterAdded:Wait()
wait(0.1)
char:SetPrimaryPartCFrame(game.Workspace.JailZone.CFrame)
end
end)
for _, v in pairs(player.Character:GetChildren()) do
if v:IsA("Tool") then
v:Destroy()
local char = player.CharacterAdded:Wait()
if timedata <= 0 then
timedata = 0
wait(0.1)
char:SetPrimaryPartCFrame(game.Workspace.SpawnZone2.CFrame)
player:SetAttribute("Jail", nil)
remotes.CraftBackpack:FireClient(player, false)
playeradm = ""
playerreas = ""
player.PlayerGui.UI.NotificationsList.Visible = false
player.PlayerGui.UI.NotificationsList.Jail.Title.Text = ""
end
end
end
end
end
end)
This part kinda looks like you want it to happen after the timer’s run out, right? Shouldn’t you add an “end” after the “while” command to close off the timer mechanismus? Again, I don’t know exactly.