Emergency service vehicle scripts interfering with remove vehicles

sorry for confusing title

My main issue is that i have two scripts which are interfering one way…

  • Delete script (which Deletes/Removes vehicles)
  • Emergency service (ELS) lights script (Which makes police lights function)

The delete script works but it’s allways interfering with a script called ‘‘pickup’’ which i’ve seen in all vehicles (so far) and the emergency servicevehicles dependent on that script.
When this script is in the vehicle you cant remove it with the button that removes player owned/player driven vehicles.

If the script (Pickup) is removed the emergency service lights works perfectly fine to remove the car but heres the issue the lights dosen’t work so i either have to pick lights or no lights. My scripting experince and knowledge is very limited

The ‘pickup’ named script:

seat = script.Parent
s = script
---------------------------------------------------------------
function onChildAdded(child)
	if child.Name == "SeatWeld" then
		local human = child.part1.Parent:findFirstChild("Humanoid") 
		if (human ~= nil) then
			print("Human IN")
			seat.SirenControl.Control.CarName.Value = human.Parent.Name.."'s Car"
			seat.Parent.Name = human.Parent.Name.."'s Car"
			s.Parent.SirenControl:clone().Parent = game.Players:findFirstChild(human.Parent.Name).PlayerGui
			seat.Start:Play()
			wait(1)
			seat.Start:Stop()
			seat.Engine:Play()
		end
	end
end

function onChildRemoved(child)
	if (child.Name == "SeatWeld") then	
		local human = child.part1.Parent:findFirstChild("Humanoid") 
		if (human ~= nil) then
			print("Human IN")
			seat.SirenControl.Control.CarName.Value = human.Parent.Name.."'s Car"
			seat.Parent.Name = human.Parent.Name.."'s Car"
			game.Players:findFirstChild(human.Parent.Name).PlayerGui.SirenControl:remove()
			seat.Engine:Stop()
		end
	end
end


script.Parent.ChildAdded:connect(onChildAdded)
script.Parent.ChildRemoved:connect(onChildRemoved)

The Delete script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local DeleteCarEvent = ReplicatedStorage:WaitForChild("DeleteCar")
local player = game.Players.LocalPlayer

game.Workspace.ChildAdded:Connect(function(Added)
	if Added.Name == player.Name .. 'sCar' then
		script.Parent.Visible = true
	end
end)

script.Parent.MouseButton1Down:Connect(function()
	local Car = game.Workspace:FindFirstChild(player.Name .. 'sCar')
	if Car then
		script.Parent.Visible = false
		for i, v in pairs(Car:GetDescendants()) do
			if v:IsA("VehicleSeat") or v:IsA("Seat") then
				if v.Occupant and v.Occupant:IsA("Humanoid") then
					v.Occupant.Sit = false
				end
			end
		end
		wait()
		DeleteCarEvent:FireServer(Car)
	end
end)

I tried ‘adjusting’ some lines in both scripts but my attempts was not successful, i feel bad brining this issue on here but im only using this as my last resort…

Any sort of help is appricated.

  • Dave
3 Likes

Sorry if this is no good but it will be to others. Use this pickup script in the vehicles seat to recognize the player and the car took me awhile to figure this out at first.

seat = script.Parent
s = script
---------------------------------------------------------------
function onChildAdded(child)
	if child.Name == "SeatWeld" then
		local human = child.part1.Parent:findFirstChild("Humanoid") 
		if (human ~= nil) then
			print("Human IN")
			seat.SirenControl.Control.CarName.Value = human.Parent.Name.."Car"
			seat.Parent.Name = human.Parent.Name.."Car"
			s.Parent.SirenControl:clone().Parent = game.Players:findFirstChild(human.Parent.Name).PlayerGui
			s.Parent.RDetector:clone().Parent = game.Players:findFirstChild(human.Parent.Name).PlayerGui
			seat.Start:Play()
			wait(1)
			seat.Start:Stop()
			seat.Engine:Play()
		end
	end
end

function onChildRemoved(child)
	if (child.Name == "SeatWeld") then	
		local human = child.part1.Parent:findFirstChild("Humanoid") 
		if (human ~= nil) then
			print("Human OUT")
			seat.SirenControl.Control.CarName.Value = human.Parent.Name.."Car"
			seat.Parent.Name = human.Parent.Name.."Car"
			game.Players:findFirstChild(human.Parent.Name).PlayerGui.SirenControl:remove()
			game.Players:findFirstChild(human.Parent.Name).PlayerGui.RDetector:remove()
			seat.Engine:Stop()
		end
	end
end


script.Parent.ChildAdded:connect(onChildAdded)
script.Parent.ChildRemoved:connect(onChildRemoved)

Hope this helps out!!!