hiii, I’m in process of remaking my door system into vehicle station system which allows players to spawn certain vehicle infront of the station.
The issue I have is after you spawn a car it doesn’t prevent you from spawning another one inside the previous one. I tried using :GetTouchingParts() to detect is anything in the spawning hitbox however it didn’t really work.
How can I prevent spawning second car if there are any parts inside the “Colision” part which I use as a hitbox?
Here is the code, parts which wouldn’t be useful were purposely removed
local ServerScriptService = game:GetService("ServerScriptService")
local VehicleStorage = game:GetService("ServerStorage"):WaitForChild("Vehicles")
local TweenService = game:GetService("TweenService")
local CollectionService = game:GetService("CollectionService")
local TaggedStations = CollectionService:GetTagged("VehicleStation")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local SoundSystem = game.Workspace:WaitForChild("_SOUND_SYSTEM").DoorSounds
local RepairEvent = ReplicatedStorage:WaitForChild("Events").SystemOverrideEvent
local NotifyEvent = game:GetService("ReplicatedStorage"):WaitForChild("Events"):WaitForChild("Notify")
--\\\: SFX
local KeycardGrantedSFX = SoundSystem.Keycard_Accepted
local KeyCardDeniedSFX = SoundSystem.Keycard_Denied
function SpawnVehicle(Vehicle, newPosition)
if VehicleStorage:FindFirstChild(Vehicle) ~= nil then
local newVehicle = VehicleStorage:FindFirstChild(Vehicle):Clone()
newVehicle:SetPrimaryPartCFrame(newPosition)
newVehicle.Parent = game.Workspace.MapElements.Vehicles
print("Vehicle Spawned")
return true
else
warn("Invalid Vehicle")
return false
end
end
for _, Station in pairs(TaggedStations) do
local SoundBlock = Station.Model.Screen
local ProximityPrompt = Station.Trigger.ProximityPrompt
local KeycardAccess = Station.KeycardAccess
local KeycardReader = Station.KeyCardReader1
local VehicleType = Station.VehicleType.Value
local VehiclePosition = Station.VehiclePosition
local Ready = true
local function Triggered(Player)
if not Ready then
return
end
Ready = false
if ProximityPrompt.Enabled and KeycardAccess:FindFirstChild(KeycardRank).Value then -- Granted
ProximityPrompt.Enabled = false
KeycardReader.KeyCardReader.Light.Color = COLOR_SCHEME.Success
PlaySoundAsync(KeycardGrantedSFX, SoundBlock)
local Collisions = VehiclePosition.Colision:GetTouchingParts()
if #Collisions == 0 then
--Sucess
SpawnVehicle(VehicleType, VehiclePosition:GetPrimaryPartCFrame()) -- Awaits a return
else
NotifyEvent:FireClient(Player, "Interaction Failed", "Please ensure that spawning area is empty")
end
wait(3)
KeycardReader.KeyCardReader.Light.Color = COLOR_SCHEME.Default
ProximityPrompt.Enabled = true
Ready = true
else --Denied
KeycardReader.KeycardReader.Light.Color = COLOR_SCHEME.Failed
PlaySoundAsync(KeyCardDeniedSFX, SoundBlock)
wait(2)
KeycardReader.KeycardReader.Light.Color = COLOR_SCHEME.Default
Ready = true
return
end
end
ProximityPrompt.Triggered:Connect(Triggered)
end