So I'm making a tool that points towards the nearest piece of scrap metal, it finds the nearest scrap but when rotating the pointer it will also rotate the player and cause them to fly everywhere please help, I have no idea how to fix this
Heres my code:
--Define Variables
local CAS = game:GetService("ContextActionService")
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local Tool = script.Parent
local character
if not player.Character then
print("waiting for character")
player.CharacterAdded:wait();
character = player.Character
else
character = player.Character
end
local hum = character:WaitForChild("HumanoidRootPart")
local equipped = false
local Model = workspace.Scrap
local Core = hum
local closest
local Pointer = Tool.Point
function GetDistanceFromChildren()
local Position_Contain = {}
for Index,Child in pairs(Model:GetChildren()) do
table.insert(Position_Contain,Index,(Child.Position - Core.Position).Magnitude)
end
for Index,Child in pairs(Model:GetChildren()) do
if (Core.Position - Child.Position).Magnitude == math.min(unpack(Position_Contain)) then
return Child
end
end
end
function Equip()
equipped = true
while equipped do
closest = GetDistanceFromChildren()
print(closest)
Pointer.CFrame = CFrame.new(Pointer.Position, closest.Position)
wait()
end
end
function Unequip()
equipped = false
end
Tool.Equipped:Connect(Equip)
Tool.Unequipped:Connect(Unequip)
Heres whats happening when I equip it: https://www.youtube.com/watch?v=SB6YMqNXqsg&feature=youtu.be
Please help, although its amazing as hell its not what its supposed to be

14 comments
Its unanchored and welded so idk whats happening
can i take a look maybe? i'm going to bed right now but it would be nice to debug it tomorrow moring
Actually, come to think of it. It might be your welds.
yeah probably
https://www.roblox.com/library/3767665052/My-Weld-Script try out this weld script maybe and see if anything changes
Nothing changed thanks for your help tho
do you mind if i take a look?
Go ahead
how do i get the model?
https://www.roblox.com/library/3863118998/Navigator, youll need a folder named scrap with parts in for it to work btw, also I think I need to rotate the welds or something, but I cant find out how to make it rotate to point towards the parts so ye
not for sale
gucci ill take a look at it
yeah... right im dum, its for sale now
I'm not sure. Going to go to bed and leave it for the morning. Definitely an issue with the welds and the CFrame though.