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 9 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
9 years ago

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


local function in_Range(part1,part2,range) if (part1.Position - part2.Position).magnitude <= range then return true -- alternatively -- return part2 end return false -- alternatively -- return nil end debounce = false while wait(0.5) do if in_Range(game.Workspace.gate,game.Workspace.car,30) == true then if debounce == false then debounce = true game.Workspace.gate.CanCollide = false wait(3) game.Workspace.gate.CanCollide = true debounce = false end end end

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

while wait(0.5) do

    if debounce == false then debounce = true

        local carModel = game.Workspace.carModel:GetChildren()

        for i = 1, #carModel do
            if in_Range(game.Workspace.gate,carModel[i],30) == false then
                debounce = false
                break
            end
        end

        if debounce == true then
            game.Workspace.gate.CanCollide = false
            wait(3)
            game.Workspace.gate.CanCollide = true
        end
    debounce = false end

end

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

0
xD AmVolt 60 — 9y
Ad

Answer this question