How do I change this from using magnitude, to using GetPartsInPart? I need the Add functions to work when inside the part, and the remove after you exit the part.
wait(1)
local Players = game:GetService("Players")
local part = script.Parent
local PG = script:WaitForChild("PlanetGravity")
local ID = script:WaitForChild("GravityID")
local Radius = 20
if ID.Value == 0 then
ID.Value = math.random(5000,10000)
PG.Value = ID.Value
end
function CloneAdd(plr)
local Gravity = plr.Character:FindFirstChild(PG.Name)
if not Gravity and plr:DistanceFromCharacter(part.Position) < Radius then
PG:Clone().Parent = plr.Character
end
end
function CloneRemove(plr)
local Gravity = plr.Character:FindFirstChild(PG.Name)
if Gravity.Value == PG.Value and plr:DistanceFromCharacter(part.Position) > Radius then
Gravity:Destroy()
end
end
--Shuttle Addition
if (_G.all_Gateships == nil) then
_G["all_Gateships"] = {}
end
ALL = _G.all_Gateships
shared["all_Gateships"] = _G.all_Gateships
--Models Addition
if (_G.all_Models == nil) then
_G["all_Models"] = {}
end
ALLMODELS = _G.all_Models
shared["all_Models"] = _G.all_Models
function CloneAddShuttle(shuttle)
local Gravity = shuttle:FindFirstChild(PG.Name)
if not Gravity and (shuttle.Engine.Position-script.parent.Position).magnitude < Radius then
PG:Clone().Parent = shuttle
end
end
function CloneRemoveShuttle(shuttle)
local Gravity = shuttle:FindFirstChild(PG.Name)
if Gravity.Value == PG.Value and (shuttle.Engine.Position-script.parent.Position).magnitude > Radius then
Gravity:Destroy()
end
end
function CloneAddModel(model)
local Gravity = model:FindFirstChild(PG.Name)
if not Gravity and (model.Handle.Position-script.parent.Position).magnitude < Radius then
PG:Clone().Parent = model
end
end
function CloneRemoveModel(model)
local Gravity = model:FindFirstChild(PG.Name)
if Gravity.Value == PG.Value and (model.Handle.Position-script.parent.Position).magnitude > Radius then
Gravity:Destroy()
end
end
while true do
wait(0.05)
for _,plr in pairs(game.Players:GetPlayers()) do
if plr.Character then
local Gravity = plr.Character:FindFirstChild(PG.Name)
if not Gravity and plr:DistanceFromCharacter(part.Position) < Radius then
CloneAdd(plr)
elseif Gravity and Gravity.Value == PG.Value and plr:DistanceFromCharacter(part.Position) > Radius then
CloneRemove(plr)
end
end
end
for i = 1, #ALL do
local Gravity = ALL[i].Model:FindFirstChild(PG.Name)
if not Gravity and (ALL[i].Model.Engine.Position-part.Position).magnitude < Radius then
CloneAddShuttle(ALL[i].Model)
elseif Gravity and Gravity.Value == PG.Value and (ALL[i].Model.Engine.Position-part.Position).magnitude > Radius then
CloneRemoveShuttle(ALL[i].Model)
end
end
for i = 1, #ALLMODELS do
local Gravity = ALLMODELS[i]:FindFirstChild(PG.Name)
if not Gravity and (ALLMODELS[i].Handle.Position-part.Position).magnitude < Radius then
CloneAddModel(ALLMODELS[i])
elseif Gravity and Gravity.Value == PG.Value and (ALLMODELS[i].Handle.Position-part.Position or ALLMODELS[i].Handle.Position-part.Position).magnitude > Radius then
CloneRemoveModel(ALLMODELS[i])
end
end
end
