Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Tool parts get farther and farther every time you equip tool while moving?

Asked by
Exsius 162
10 years ago

http://www.roblox.com/Tool-testing-place?id=179683718

When you equip the tool and Unequip while moving it like stays back.

is there any way to make it move back to the player every time you equip it?

Thanks,

Exsius ;)

I tried to use a CFrame code to bring in back to the player but it wont work

Tool = script.Parent
--WepFix = Tool.Gun  Ignore
Head = script.Parent.Parent.Parent.Character.Head




Tool.Equipped:connect(function(mouse)


     script.Parent.Gun.C0 = CFrame.new()
    script.Parent.Gun.C1 = CFrame.new(0, 1, 0) * CFrame.Angles(0,0, 0)      --Cframe

    script.Parent.Gun.Anchored = false

weld = Instance.new("Weld")
weld.Part0 = Head
weld.C0 = Head.CFrame:inverse()
weld.Part1 = script.Parent.Gun
weld.C1 = script.Parent.Gun.CFrame:inverse()
weld.Parent = script.Parent
wait(1)






end)



1 answer

Log in to vote
0
Answered by
Muoshuu 580 Moderation Voter
10 years ago

Try this out:

local Tool=script.Parent
local Player=game.Players:FindFirstChild(Tool.Parent.Name) or Tool.Parent.Parent
local Head=Player.Character.Head
local Gun=script.Parent.Gun

function Weld()
    local W=Gun:FindFirstChild("GunWeld") if W then W:destroy() end
    Gun.Anchored=true
    Head.Anchored=true
    local Weld=Instance.new("Weld",Gun)
    Weld.Name="GunWeld"
    Weld.Part0=Head
    Weld.Part1=Gun
    Weld.C0=Head.CFrame:inverse()
    Weld.C1=Gun.CFrame:inverse()
    Gun.Anchored=false
    Head.Anchored=false
end
Tool.Equipped:connect(Weld)
0
Please do not just post code, for that does not help the user to learn, please provide explanation behind answer, or else it does not help the user to expand his/her knowledge. TheeDeathCaster 2368 — 10y
0
...An idiot could tell the only thing I did was anchor and then unanchor the parts Muoshuu 580 — 10y
Ad

Answer this question