New: Nitro Boost our Discord server and receive full donation perks here on the website! Join the Scripting Helpers Discord Server to learn more! You can also Support on Patreon as always.
Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
1

Help! rotating part of tool also rotates player?

Asked by 12 days ago
Edited 12 days ago

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

1 answer

Log in to vote
1
Answered by
royaltoe 1796 Moderation Voter
12 days ago
Edited 12 days ago

Maybe your tool is anchored? You need to have it unanchored and welded or else it'll be all glitchy like this. Happens to me sometimes.

0
Its unanchored and welded so idk whats happening kikuhou 6 — 12d
0
can i take a look maybe? i'm going to bed right now but it would be nice to debug it tomorrow moring royaltoe 1796 — 12d
0
Actually, come to think of it. It might be your welds. royaltoe 1796 — 12d
0
yeah probably kikuhou 6 — 12d
View all comments (10 more)
0
https://www.roblox.com/library/3767665052/My-Weld-Script try out this weld script maybe and see if anything changes royaltoe 1796 — 12d
0
Nothing changed thanks for your help tho kikuhou 6 — 12d
0
do you mind if i take a look? royaltoe 1796 — 12d
0
Go ahead kikuhou 6 — 12d
0
how do i get the model? royaltoe 1796 — 12d
0
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 kikuhou 6 — 12d
0
not for sale royaltoe 1796 — 12d
0
gucci ill take a look at it royaltoe 1796 — 12d
0
yeah... right im dum, its for sale now kikuhou 6 — 12d
0
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. royaltoe 1796 — 12d
Ad

Answer this question