Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Disabling spawners if another vehicle is too close?

Asked by 5 years ago

I have made some ship spawners which take money, then spawn a ship when touched. The problem is, if a ship is in the way, the spawners still work, which obviously causes problems. I was planning on disabling the spawners if another ship is too close, but I have no idea how to go about it. Anyone there to point me in the right direction? Thanks in advance.

2 answers

Log in to vote
1
Answered by 5 years ago

You can use Magnitude to check if it's within a certain distance. This will be an example with the player's distance and with the ship's distance. If you'd like to check between the spawner and the ship, change the HumanoidRootPart to wherever your spawn is.

-- Add this somewhere in your touched event
-- Assuming you already got the humanoid 

local minDistance = 50 -- example. the closest it can be 
local mag = (hit.Parent.HumanoidRootPart.Position - script.Parent.Position)

if mag.Magnitude <= minDistance then
    -- code. this is all i'm giving since you only asked for a point in the right direction. 
end
0
Thank you, incapaz! Ultimate_Miner64 45 — 5y
Ad
Log in to vote
0
Answered by
vkax 85
5 years ago

There is an Enabled attribute in a spawner, you can configure it to what you would like, true or false. False being the condition you'd like it in.

Answer this question