Imagine there is a group of cars, driven by players. One of them brakes, and they are now 50+ studs away from others. How can I detect this?
Another example is when everyone brakes except one person, that one person will get their car removed because they would be 50+ studs away from the group but in front of them instead of behind them.
I have absolutely no idea on how to do this, I’m not trying to ask for a script but I’m trying to ask how I can do this. Thanks.
Ok so i believe i found a way with Models, you might be able to use WorldPivot which is pretty much the Position of the Model?
(More like a copy of the Position since it doesnt actually change the position when you do so, only when you change the origin)
plr = game.Players.LocalPlayer
char = plr.Character or plr.CharacterAdded:Wait()
while true do
wait()
local Mag = (workspace.Model.WorldPivot.Position - char.HumanoidRootPart.Position).Magnitude
if Mag > 50 then
print("Player is far away")
end
end
The only issue is that the Bounding box will resize if a item moves away
Another Solution is that you may be able to Apply a Tag to the Leading Person in the group, an detect if you are far away from there
Get all players in the game and store in an array P.
Use in ipairs to loop thru array P.
For each player in array P, compare the distance with all other players in array P.
If distance are all > 50, then player is out.
local list = workspace.Cars:GetChildren()
for _, plr in list do
local closestDist = math.huge
for _, otherPlr in list do
local dist = plr:DistanceFromCharacter(otherPlr.Character.HumanoidRootPart.Position)
if otherPlr ~= plr and dist < closestDist then
closestDist = dist
end
end
if closestDist >= 50 then
-- is far away from group
end
end