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

is there a way to do this without moving the character?

Asked by 5 years ago
Edited 5 years ago

hello, so i am trying to make a script that whenever you unequip a sword(tool) it welds to your back, i found a way to create a clone of the tool but when i try to move the CFrame of that clone (so i can make it go on the players back) the player moves to that swords new CFrame (https://gyazo.com/c0a118b444861c619be5944f56f6dc6f the player moves to the sword)

Full Script:

local onback = false
local UIS = game:GetService("UserInputService")

function BackWeld() --item must be in inventory
    if not onback then
        local player = script.Parent.Parent.Parent.Parent
        local char = player.Character
        local upperT = char.UpperTorso

        local toolclone = script.Parent.Parent:Clone()
        toolclone.Parent = game.Lighting.OnbackFolder
        toolclone.Name = 'OnbackClone'
        local clonechildren = toolclone:GetChildren()

        local model = Instance.new('Model',char)
        model.Name = 'SwordForBack'

        for i = 1 , #clonechildren do
            if clonechildren[i].ClassName == 'Part' or clonechildren[i].ClassName == 'MeshPart' then
                local ultraclone = clonechildren[i]
                ultraclone.Name = clonechildren[i].Name
                ultraclone.Parent = model
                ultraclone.CanCollide = false

                if clonechildren[i].Name == 'Handle' then
                    for i,v in pairs(model:GetChildren()) do
                        if v:IsA('MeshPart','Part') then
                            local Weld = Instance.new('Weld', model)
                            Weld.C0 = model.Handle.CFrame:inverse() * v.CFrame
                            Weld.Part0 = model.Handle
                            Weld.Part1 = v
                        end
                    end
                end
            end
        end
        local modelhandle = model.Handle

        local backWeld = Instance.new('Weld', modelhandle)
        backWeld.Name = 'Backweld'
        backWeld.Part0 = upperT
        backWeld.Part1 = modelhandle

        modelhandle.CFrame = upperT.CFrame + Vector3.new(10,0,10)
    end
end

script.Parent.Parent.Unequipped:Connect(function()
    print('Activated')
    BackWeld()
    wait(1)
end)

the part of the script that i think matters is:

        local modelhandle = model.Handle

        local backWeld = Instance.new('Weld', modelhandle)
        backWeld.Name = 'Backweld'
        backWeld.Part0 = upperT
        backWeld.Part1 = modelhandle

        modelhandle.CFrame = upperT.CFrame + Vector3.new(10,0,10)

because i think this is because i need to use a different weld but a weld constraint also doesn't work so whenever i move the 'modelhandle.CFrame' the player moves with it

if anything is unclear comment i'll try and explain it better

0
maybe the weld is forcing the character CFrame somewhere else, maybe you could try swapping P0 and P1? fanofpixels 718 — 5y
0
i tried that but the same thing happens TigerClaws454 48 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago

not sure if this will work but maybe try change

local modelhandle = model.Handle

local backWeld = Instance.new('Weld', modelhandle)
backWeld.Name = 'Backweld'
backWeld.Part0 = upperT
backWeld.Part1 = modelhandle

modelhandle.CFrame = upperT.CFrame + Vector3.new(10,0,10)

to

local modelhandle = model.Handle

local backWeld = Instance.new("Weld")
backWeld.Paren = modelhandle
backWeld.Name = "Backweld"
backWeld.Part0 = upperT
backWeld.Part1 = modelhandle

modelhandle.CFrame = upperT.CFrame + Vector3.new(10,0,10)

what i did here was first just creating the weld and then parenting it, the rest was urs, btw when u set names of something new use " instead of ', same thing when u make an Instance.new

0
thanks for trying but it still moves the character when i move the sword TigerClaws454 48 — 5y
0
hm.. Gameplayer365247v2 1055 — 5y
0
btw i forgot to type out parent, hope u did that urself otherwise that may be the reason Gameplayer365247v2 1055 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

after i started looking at free models of people doing this i found out i was doing the wrong thing, this is the fixed part if anyone in the future has the same issue:

local modelhandle = model.Handle

local backWeld = Instance.new("Weld",modelhandle)
backWeld.Name = "Backweld"
backWeld.Part0 = upperT
backWeld.Part1 = modelhandle
backWeld.C0 = CFrame.new(1,1.5,0.6)
backWeld.C0 = backWeld.C0 * CFrame.fromEulerAnglesXYZ(math.rad(-90),math.rad(300),0)

Answer this question