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

Can't get my sword to stay in the players hand? [SOLVED]

Asked by 6 years ago
Edited 6 years ago

I have a sword and when you press a key it switches into a gun then after a delay back into a sword. Everything is fine in Studio, of course...but in the game when it's switching from sword to gun the weld/position become weird. Then sword will still be equipped to the player but it will be floating off somewhere instead of in the player's hand. I created a script to for the weld to fix itself but that hasn't seemed to work.

local Player = game.Players.LocalPlayer
char = Player.Character

while wait() do
    local w1 = Instance.new("Weld", char)
    w1.Part0 = char["Right Arm"]
    w1.Part1 = script.Parent.Handle
    w1.C1 = CFrame.fromEulerAnglesXYZ(math.rad(90),0,0) *CFrame.new(0, 1.1, 0)
    --Forcing the sword to stay welded in the players hand  
end

2 answers

Log in to vote
0
Answered by 6 years ago

Fixed it. I had it removing and cloning a new sword on every keypress but I did some research and found the equip and unequip methods.

0
Glad you figured it out. It'd be good if you edited the title of this question to have "[Solved]" in the title so others won't read your question unnecessarily. chess123mate 5873 — 6y
0
Will do SimpleFlame 255 — 6y
0
I'm having the same problem, but my sword has a lot of parts, and won't stay connected to the character no matter what SirGrimZz99 0 — 2y
Ad
Log in to vote
0
Answered by 6 years ago

You don't need to weld but make sure tool.NeedHandle is true and the handle name it Handle

0
It was true and I already fixed it, thanks. SimpleFlame 255 — 6y

Answer this question