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

How do I tell a script to find a model within a certain range of it?

Asked by 10 years ago

What is the function for finding a model if its within a certain range of a block? I guess it would be similar to the

function get_nearby_player()

function, but instead of a player it would be for a model. I don't know what function to use for that since as far as I know there isn't a "function if_block_distance < (distance) function as far as I know...

Thanks for any help!

1 answer

Log in to vote
0
Answered by
ZeroBits 142
10 years ago

well, it depends, if you want to know when a specific part is in range, than this should work;

01local function in_Range(part1,part2,range)
02    if (part1.Position - part2.Position).magnitude <= range then
03        return true
04        -- alternatively
05        -- return part2
06    end
07    return false
08    -- alternatively
09    -- return nil
10end
11 
12debounce = false
13 
14while wait(0.5) do
15 
View all 24 lines...

or, if you want to see if any part in a model is in range, then replace the last part with this;

01while wait(0.5) do
02 
03    if debounce == false then debounce = true
04 
05        local carModel = game.Workspace.carModel:GetChildren()
06 
07        for i = 1, #carModel do
08            if in_Range(game.Workspace.gate,carModel[i],30) == false then
09                debounce = false
10                break
11            end
12        end
13 
14        if debounce == true then
15            game.Workspace.gate.CanCollide = false
View all 21 lines...

or if you want to know when any part at all is in range, I hate you.

0
xD AmVolt 60 — 10y
Ad

Answer this question