Prisoner script not working?

This prisoner script i made does not work, it used to and now is just broken completely, any help?

local Players = game:GetService("Players")

local function PlayerIsInJail(Player)
	if Player.Team.Name == "Prisoner" then
		return true
	end
end

local function uncrime(Player)
	Player.Team = game:GetService("Teams").Neutral
	print("players team = neutral")
	Player:WaitForChild("stats").Arrested = false
	print("players arrested value = false")
	Player:LoadCharacter()
	Player.PlayerGui.PrisonTime:Destroy()
	print("players prisontime gui destroyed")
end

local function GetPlayerJailTime(Player)
	return Player:WaitForChild("stats"):WaitForChild("JailTime").Value
end

local function HandlePlayer(Player)
	
	local function HandleCharacter(Player, Character)
		if PlayerIsInJail(Player) then
			
			while GetPlayerJailTime(Player) > 0 do
				wait(1)
				Player:WaitForChild("stats"):WaitForChild("JailTime").Value = Player:WaitForChild("stats"):WaitForChild("JailTime").Value - 1
				end
		else
			uncrime(Player)
		end
		end
	
	if Player.Character then
		HandleCharacter(Player, Player.Character)
	end	
		
end	
	
for _, Player in pairs(Players:GetPlayers()) do
	HandlePlayer(Player)
	end
1 Like

You’re attempting to compare an Instance with a BoolValue in your uncrime local function…? Could that be the issue?

Player:WaitForChild("stats").Arrested.Value = false
1 Like

your right, its working now, but now its looped, how do i fix the loop, it just keeps doing the :LoadCharacter on me

local Players = game:GetService("Players")

local function PlayerIsInJail(Player)
	if Player.Team.Name == "Prisoner" then
		return true
    else
        return false
	end
end

local function uncrime(Player)
	Player.Team = game:GetService("Teams").Neutral
    print(Player.Team)
	Player:WaitForChild("stats").Arrested.Value = false
	print("players arrested value = false")
	Player:LoadCharacter()
	Player.PlayerGui.PrisonTime:Destroy()
	print("players prisontime gui destroyed")
end

local function GetPlayerJailTime(Player)
	return Player:WaitForChild("stats"):WaitForChild("JailTime").Value
end

local function HandlePlayer(Player)
	
	local function HandleCharacter(Player, Character)
		if PlayerIsInJail(Player) then
			
			while GetPlayerJailTime(Player) > 0 do
				wait(1)
				Player:WaitForChild("stats"):WaitForChild("JailTime").Value = Player:WaitForChild("stats"):WaitForChild("JailTime").Value - 1
				end
		else
			uncrime(Player)
		end
		end
	
	if Player.Character then
		HandleCharacter(Player, Player.Character)
	end	
		
end	
	
for _, Player in pairs(Players:GetPlayers()) do
	HandlePlayer(Player)
	end

Could you try this maybe?

its still refreshing me, i was thinking about just adding some random check but idk?

This function might be returning false each time maybe? Could you try checking for the TeamColor instead? :thinking:

I just updated the script to this, i changed it from a function to just after its done looping, idk if it works tho?

local Players = game:GetService("Players")

local function PlayerIsInJail(Player)
	if Player.Team.Name == "Prisoner" then
		return true
	else
		return false
	end
end

local function GetPlayerJailTime(Player)
	return Player:WaitForChild("stats"):WaitForChild("JailTime").Value
end

local function HandlePlayer(Player)

	local function HandleCharacter(Player, Character)
		if PlayerIsInJail(Player) then

			while GetPlayerJailTime(Player) > 0 do
				wait(1)
				Player:WaitForChild("stats"):WaitForChild("JailTime").Value = Player:WaitForChild("stats"):WaitForChild("JailTime").Value - 1
			end
			Player.Team = game:GetService("Teams").Neutral
			print(Player.Team)
			Player:WaitForChild("stats").Arrested.Value = false
			print("players arrested value = false")
			Player:LoadCharacter()
			Player.PlayerGui.PrisonTime:Destroy()
			print("players prisontime gui destroyed")
		end
	end

	if Player.Character then
		HandleCharacter(Player, Player.Character)
	end	

end	

for _, Player in pairs(Players:GetPlayers()) do
	HandlePlayer(Player)
end

Are you getting any results? :thinking: