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

Welding Sword to surface problems?

Asked by 4 years ago

I am trying to create a serverscript in which it catches a remote event fired by when I press C, the sword on my back will weld onto my hand, and when I press C again, it will switch to the position it was on my back.

I can get the position of the sword just fine, but the orientation of the sword somehow fucks it up.

I was told once to use WeldConstraints, but I can only find the best tutorials online to be about normal Welds, so I just am using those at the moment.

Here is my problematic script (it may be sort of long, and I'm not sure everything in it is even necessary so hang with me, because I am not a very experienced scripter):

local blade = script.Parent.Parent.Blade

local rep = game:WaitForChild("ReplicatedStorage")
local press = rep:WaitForChild("Equip")

local function Equip(player, weldSwordModel, EquippedValue, UpperTorso, character)

    if EquippedValue == false then
        print("caught")
        weldSwordModel.Parent = workspace
        local weld = Instance.new("Weld", workspace)

        weld.Part0 = blade
        weld.C0 = UpperTorso.CFrame:inverse()
        weld.Part1 = UpperTorso
        weld.C1 = UpperTorso.CFrame:inverse()
        weld.C0 = weld.C0 * CFrame.new(0, 0, 0)
        weld.C0 = CFrame.Angles(math.rad(-45), math.rad(90), math.rad(-90))

        wait(1)
        EquippedValue = true

    end

end 

press.OnServerEvent:Connect(Equip)

The result of pressing C is this: https://gyazo.com/a6fd00beb5784ad934d2de14ca6109aa

I'm not sure why it does this. I don't know much about CFrame and quite frankly before trying this I've never messed with CFrame, can anyone tell me what is wrong? I was told perhaps to use CFrame.lookAt instead of CFrame.Angles but everyone I talked to only knew how to use CFrame.Angles so you can see why I am using it.

Please, if you're reading and have a solution, inform me!

Thank you!

0
Sorry mate can't help you with that but is it possible for you to just use the tool handle? That way the roblox will autoamtically weld the sword to your hand. But if you can't use it in this case then my post is useless imKirda 4491 — 4y
0
no i cant use the tool, it isnt the same 1ZestyChesty1 2 — 4y

Answer this question