function AddForce(Proton, Neutron)
local LineForce = Instance.new("LineForce", Proton)
local att0 = Instance.new("Attachment", Proton)
local att1 = Instance.new("Attachment", Neutron)
att0.Name = "Attachment0"
att1.Name = "Attachment1"
LineForce.InverseSquareLaw = true
LineForce.ReactionForceEnabled = true
LineForce.ApplyAtCenterOfMass = true
LineForce.Magnitude = Proton:GetMass()
LineForce.Attachment0 = att0
LineForce.Attachment1 = att1
end
function ReturnAllNeutronsAttached(Proton)
local NeutronsAttached = {}
for i,v in pairs(Proton:GetChildren()) do
if v:IsA("LineForce") then
table.insert(NeutronsAttached, v.Attachment1.Parent)
end
end
return NeutronsAttached
end
script.Parent.Touched:Connect(function(hit)
local Proton = script.Parent
local LineForce = Proton:FindFirstChild("LineForce")
if hit.Name == "Neutron" and LineForce then
local Neutron = hit
local CurrentNeutrons = ReturnAllNeutronsAttached(Proton)
if table.find(CurrentNeutrons, Neutron) then
else
AddForce(Proton, Neutron)
end
else
if hit.Name == "Neutron" then
local Neutron = hit
AddForce(Proton, Neutron)
end
end
end)
1 Like
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.