The goal is pretty simple, Find a parts closest point to another part (They Would Be Touching) OR another way to stick a ball to any type of object thats tagged
Im using a vector force to apply force to the wall therefore Stoping it from falling and keeping it stuck too the wall
Here is my code (In this segment but it should be enough):
cs:GetInstanceAddedSignal("Sticky"):Connect(function(Plr)
if Plr:IsA("Player") then
local Attachment = Instance.new("Attachment")
Attachment.Parent = Plr.Character.HumanoidRootPart
Attachment.Name = "Attachment"
local Force = Instance.new("VectorForce")
Force.Parent = Plr.Character.HumanoidRootPart
Force.Name = "Force"
Force.Attachment0 = Attachment
Force.Force = Vector3.new(0,0,0)
local LastTouchedObject = nil
Plr.Character.HumanoidRootPart.Touched:Connect(function(T)
if T:HasTag("Stickable") then
LastTouchedObject = T
print()
end
end)
Plr.Character.HumanoidRootPart.TouchEnded:Connect(function(T)
if T:HasTag("Stickable") then
LastTouchedObject = nil
end
end)
repeat
task.wait(0.1)
if LastTouchedObject then
Force.Force = Vector3.new(500, 500, 500) * LastTouchedObject.CFrame.LookVector
print(Force.Force)
else
Force.Force = Vector3.new(0,0,0)
end
until false
end
end)
Any help is appreciated