#How do I check if there was already jeep within the same position?

1 messages · Page 1 of 1 (latest)

hard osprey
#
local Prompt = script.Parent
local jeep = game.ServerStorage:WaitForChild("Jeep")

Prompt.Triggered:Connect(function()
    
    local cloneJeep = jeep:Clone()
        
    local TargetPosition = Vector3.new(146.5, 42.525, 169.5)        
    cloneJeep:PivotTo(CFrame.new(TargetPosition))
    
    cloneJeep.Parent = workspace
end)

young saddle
#

store all the positions in a table

#

but also your only going to have 1 able to spawn in that case because your spawning it in a set position

fast bison
#

if you know how to raycast, you could use that to see if there's a jeep below a certain point

#

or, use :GetPartsInPart to find jeep parts

deft apex
#
local parts = workspace:GetPartBoundsInBox(CFrame.new(TargetPosition), jeep:GetExtentsSize())

local jeepFound = false
for _, part in parts do
  if part:FindFirstAncestorWhichIsA("Model").Name == jeep.Name then
    jeepFound = true
    break
  end
end
fast bison
#

^ that would work

#

though, i think PartsInPart is a bit easier to use + accounts for rotation/is easier to adjust, generally

deft apex
#

theres probably a better way to check if a model is a jeep

hard osprey
#

thats's new for me

fast bison
#

tbh, just FindFirstAncestor( jeep name )

fast bison
#

apolocheese for stealing your thunder @deft apex but adjusted code:

local parts = workspace:GetPartsInPart(workspace.JeepSpawnBox)

local jeepFound = false
for _, part in parts do
  if part:FindFirstAncestor(jeepname) then
    jeepFound = true
    break
  end
end

if jeepFound then
 --blah blah blah
end
#

something like that

deft apex
#

whered you get jeepspawnbox from

fast bison
#

made it up

#

you'd add a jeep spawn part and make it transparent etc to use as the checking box

#

to be clear @hard osprey

#

and call it JeepSpawnBox or adjust the code for the name of it or w/e

hard osprey
#

ok thanks 👍

vital raft
#

Life would be pain and laggy without :getpartsinpart()