game.Players.PlayerAdded:Connect(function(player)
local playerInCar = Instance.new("BoolValue") -- creating a boolean to check wether the player is inside a car or not
playerInCar.Name = "PlayerInCar"
playerInCar.Value = false
playerInCar.Parent = player
playerInCar:GetPropertyChangedSignal("Value"):Connect(function() -- should fire whenever the player goes inside a car
if playerInCar.Value == true then
local streetlights = workspace.Streetlights:GetChildren()
repeat
for i, v in pairs(streetlights) do
if v:IsA("Model") then
local distance = (playerCar.Front.Position-v:GetPrimaryPartCFrame().p).magnitude
if distance < 5 and carSpeed > 20 then -- check if the distance is lower than 5 studs and the speed of the car is over 20
-- unanchor streetlight and make it fall to the direction where it is supposed to fall
end
end
end
wait(0.03)
until playerInCar.Value == false
end
end)
end)