task.wait(.1)local E=game:GetService("\080\108\097\121\101\114\115")local F={"\080\108\097\121\101\114\049"}local S=BrickColor.new("\077\101\100\105\117\109 \115\116\111\110\101 \103\114\101\121")local Y={}local X=script.Parent local r=script.Car local B=nil local A=30 local o=30 local i=false local function z()script.Parent.Parent.Sound.Timeout.Enabled=true repeat script.Parent.Parent.Sound.Timeout.TextLabel.Text=tostring(o)..""script.Parent.Parent.Sound.Timeout.TextLabel.TextScaled=false o-=1 if o==0 then X.Parent:Destroy()end task.wait(1)until o==0 or B~=nil o=A script.Parent.Parent.Sound.Timeout.Enabled=false end local function f(E)local F=r:Clone()F.Parent=E.PlayerGui F.Frame.Seat.Value=script.Parent F.Frame.LocalScript.Disabled=false end script.Parent.ChildAdded:connect(function(F)if F:IsA("\087\101\108\100")and F.Name=="\083\101\097\116\087\101\108\100"then print(F.Name)local Y=F.Part1.Parent local r=E:GetPlayerFromCharacter(Y)if B==nil and r.TeamColor==S then B=r f(r)X:SetNetworkOwnershipAuto()elseif B~=nil and r.Name==B.Name then print("\119\101\108\099\111\109\101 \098\097\099\107")X:SetNetworkOwnershipAuto()else X.Disabled=true print("\066\111\111\116\101\100 \080\108\097\121\101\114\046")task.wait(1.5)X.Disabled=false end elseif F:IsA("\073\110\116\086\097\108\117\101")then B=nil script.Parent.Parent.Parent=game.Workspace.VehiclesFolder.UnclaimedVehicles X:SetNetworkOwnershipAuto()z()end end)


task.wait(0.1)
local Players = game:GetService("Players")
local Check = {"Player1"}
local TeamColor = BrickColor.new("Medium stone grey")
local Blacklist = {}
local seat = script.Parent
local gui = script.Car
local owner = nil
local deletetime = 30
local currTime = 30
local timerdebounce = false

local function StartTimer()
	script.Parent.Parent.Sound.Timeout.Enabled = true
	repeat
		script.Parent.Parent.Sound.Timeout.TextLabel.Text = tostring(currTime) .. ""
		script.Parent.Parent.Sound.Timeout.TextLabel.TextScaled = false
		currTime -= 1
		if currTime == 0 then
			seat.Parent:Destroy()
		end
		task.wait(1)
	until currTime == 0 or owner ~= nil
	currTime = deletetime
	script.Parent.Parent.Sound.Timeout.Enabled = false
end

local function GiveGUI(plr)
	local guiClone = gui:Clone()
	guiClone.Parent = plr.PlayerGui
	guiClone.Frame.Seat.Value = script.Parent
	guiClone.Frame.LocalScript.Disabled = false
end

script.Parent.ChildAdded:connect(function(it)
	if it:IsA("Weld") and it.Name == "SeatWeld" then
		print(it.Name)
		local tempCharacter = it.Part1.Parent
		local tempPlayer = Players:GetPlayerFromCharacter(tempCharacter)

		if owner == nil and tempPlayer.TeamColor == TeamColor then
			owner = tempPlayer
			GiveGUI(tempPlayer)
			seat:SetNetworkOwnershipAuto()
		elseif owner ~= nil and tempPlayer.Name == owner.Name then
			print("welcome back")
			seat:SetNetworkOwnershipAuto()
		else
			seat.Disabled = true
			print("Booted Player.")
			task.wait(1.5)
			seat.Disabled = false
		end
	elseif it:IsA("IntValue") then
		owner = nil
		script.Parent.Parent.Parent = game.Workspace.VehiclesFolder.UnclaimedVehicles
		seat:SetNetworkOwnershipAuto()
		StartTimer()
	end
end)
