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

For some reason my arrest system is not working, any help?

Asked by 5 years ago
Edited by User#5423 5 years ago

The script works fine, but it doesnt keep the player in jail if they reset. Heres the script ``` JailPos = script.Parent.JailPosition.Value

FreemanPosition = Vector3.new(5, 4, 191)

JailedFolder = script.Parent.JailedPlayers

function TeleportPlayer(Plyer,Pos)

if Plyer.Character ~= nil then

local HMRP = Plyer.Character:FindFirstChild("HumanoidRootPart")

if HMRP then

HMRP.CFrame = CFrame.new(Pos)

end

end

end

function PlayerFromName(Nam)

local Search = game.Players:FindFirstChild(Nam)

if Search then return Search else return nil end

end

function GiveJailGui(Plyname)

local Play = PlayerFromName(Plyname)

if Play then

if Play.PlayerGui then

local JG = script.JailedGui:Clone()

JG.Parent = Play.PlayerGui

JG.GUpdater.Disabled = false

end end end

function GiveFreemanGui(Plyname)

local Play = PlayerFromName(Plyname)

if Play then

if Play.PlayerGui then

local FG = script.PlayerFree:Clone()

FG.Parent = Play.PlayerGui

FG.CloseScript.Disabled = false

end end end

function ClearName(PlyName)

local fin = JailedFolder:GetChildren()

for i = 1,#fin do if fin[i].Name == PlyName then

fin[i]:Destroy()

end end

end

function HandleJailTime(PlyName,TimeToServe)

ClearName(PlyName)

local Timer = Instance.new("IntValue")

Timer.Name = PlyName

Timer.Parent = JailedFolder

Timer.Value = TimeToServe

coroutine.wrap(function()

for i = 1,TimeToServe do

Timer.Value = Timer.Value - 1

wait(1)

end

Timer.Value = 0 wait(1) Timer:Destroy()

end)()

end

function JailPlayer(Caller,PlyN)

local JPlayer = PlayerFromName(PlyN)

if JPlayer then

if JPlayer.Backpack then JPlayer.Backpack:ClearAllChildren() end

if not JPlayer.PlayerGui:FindFirstChild("JailedGui") then

HandleJailTime(PlyN,90)

TeleportPlayer(JPlayer,JailPos)

GiveJailGui(PlyN)

end end

end

script.Parent.OnServerEvent:connect(function(Caller,Prisoner,format)

if Caller then if Prisoner ~= nil then if format ~= nil then

if format == "Jail" then

JailPlayer(Caller,Prisoner)

elseif format == "Confirm" then

local CGui = script.JConfirmGui:Clone()

local CopPGUI = Caller:FindFirstChild("PlayerGui")

if CopPGUI then

if not CopPGUI:FindFirstChild("JConfirmGui") then

CGui.Parent = CopPGUI

CGui.TargetPlayer.Value = Prisoner.Name

CGui.ArrestPlayer.Disabled = false

end end

elseif format == "Freeman" then

TeleportPlayer(Caller,FreemanPosition)

ClearName(Caller.Name)

GiveFreemanGui(Caller.Name)

elseif format == "BackToJail" then

TeleportPlayer(Caller,JailPos)

elseif format == "BackToJailNP" then -- where when the player respawns, they should be in jail still, which for some reason does not.

TeleportPlayer(Caller,JailPos)

GiveJailGui(Caller.Name)

elseif format == "ClearJGUIs" then

local ser = Caller:FindFirstChild("PlayerGui") if ser then

local search = ser:GetChildren()

for i = 1,#search do

if search[i].Name == "JConfirmGui" or search[i].Name == "JailedGui" or search[i].Name == "PlayerFree" then

search[i]:Destroy()

end end end

end

end end end

end) ```

0
Maybe you can attach it as a script so it's easier to read? MrDaniel_TX 5 — 5y
0
use code block pls User#5423 17 — 5y
0
Okay Pooglies 7 — 5y

1 answer

Log in to vote
0
Answered by 4 years ago

Here is that script but in a code block. Next time please consider posting questions with a cod block.


JailPos = script.Parent.JailPosition.Value FreemanPosition = Vector3.new(5, 4, 191) JailedFolder = script.Parent.JailedPlayers function TeleportPlayer(Plyer,Pos) if Plyer.Character ~= nil then local HMRP = Plyer.Character:FindFirstChild("HumanoidRootPart") if HMRP then HMRP.CFrame = CFrame.new(Pos) end end end function PlayerFromName(Nam) local Search = game.Players:FindFirstChild(Nam) if Search then return Search else return nil end end function GiveJailGui(Plyname) local Play = PlayerFromName(Plyname) if Play then if Play.PlayerGui then local JG = script.JailedGui:Clone() JG.Parent = Play.PlayerGui JG.GUpdater.Disabled = false end end end function GiveFreemanGui(Plyname) local Play = PlayerFromName(Plyname) if Play then if Play.PlayerGui then local FG = script.PlayerFree:Clone() FG.Parent = Play.PlayerGui FG.CloseScript.Disabled = false end end end function ClearName(PlyName) local fin = JailedFolder:GetChildren() for i = 1,#fin do if fin[i].Name == PlyName then fin[i]:Destroy() end end end function HandleJailTime(PlyName,TimeToServe) ClearName(PlyName) local Timer = Instance.new("IntValue") Timer.Name = PlyName Timer.Parent = JailedFolder Timer.Value = TimeToServe coroutine.wrap(function() for i = 1,TimeToServe do Timer.Value = Timer.Value - 1 wait(1) end Timer.Value = 0 wait(1) Timer:Destroy() end)() end function JailPlayer(Caller,PlyN) local JPlayer = PlayerFromName(PlyN) if JPlayer then if JPlayer.Backpack then JPlayer.Backpack:ClearAllChildren() end if not JPlayer.PlayerGui:FindFirstChild("JailedGui") then HandleJailTime(PlyN,90) TeleportPlayer(JPlayer,JailPos) GiveJailGui(PlyN) end end end script.Parent.OnServerEvent:connect(function(Caller,Prisoner,format) if Caller then if Prisoner ~= nil then if format ~= nil then if format == "Jail" then JailPlayer(Caller,Prisoner) elseif format == "Confirm" then local CGui = script.JConfirmGui:Clone() local CopPGUI = Caller:FindFirstChild("PlayerGui") if CopPGUI then if not CopPGUI:FindFirstChild("JConfirmGui") then CGui.Parent = CopPGUI CGui.TargetPlayer.Value = Prisoner.Name CGui.ArrestPlayer.Disabled = false end end elseif format == "Freeman" then TeleportPlayer(Caller,FreemanPosition) ClearName(Caller.Name) GiveFreemanGui(Caller.Name) elseif format == "BackToJail" then TeleportPlayer(Caller,JailPos) elseif format == "BackToJailNP" then -- where when the player respawns, they should be in jail still, which for some reason does not. TeleportPlayer(Caller,JailPos) GiveJailGui(Caller.Name) elseif format == "ClearJGUIs" then local ser = Caller:FindFirstChild("PlayerGui") if ser then local search = ser:GetChildren() for i = 1,#search do if search[i].Name == "JConfirmGui" or search[i].Name == "JailedGui" or search[i].Name == "PlayerFree" then search[i]:Destroy() end end end end end end end end)

I did not format anything from the script but only made it have a code block.

Ad

Answer this question