--credit to matt for fixing 


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)
