Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why does my script not move the correct part when I welded something?

I made a script where it welds a part to Left Hand, but it keeps welding Left Hand to a Part how do I fix this? Here's my script but please refrain from saying "You're Dumb" instead of answering the question like the responses I normally get. Also I already tried flipping Part0 and Part1 and it didn't work, so are there other reason this could be occuring?

plr = game:GetService("Players").LocalPlayer
char = plr.character
rad = math.rad
s = char:WaitForChild('WhiteBlack')
sw = s.Handle
wc = s.Handle.WeldConstraint
local w = Instance.new('Weld', sw)
lh = char:WaitForChild('LeftHand')



function onKeyDown(inputObject, gameProcessedEvent)
	if inputObject.KeyCode == Enum.KeyCode.Q then
		print("Q was pressed")
		w.Part0 = sw
		w.Part1 = lh
		sw.WeldConstraint.Enabled = false
		w.C0 = CFrame.new(0,0,0) * CFrame.Angles(rad(45),rad(0),rad(0))
		
	end
end
 
game:GetService("UserInputService").InputBegan:connect(onKeyDown)

3 comments

0

You're Dumb

0

lmaoo

0

Make sure your part is not Anchored.

2 answers

✓ Accepted answer
local plr = game.Players.LocalPlayer
local char = plr.Character
local s = char:WaitForChild("WhiteBlack")
local sw = s:WaitForChild("Handle")
local wc = sw:WaitForChild("WeldConstraint")
local w = Instance.new("Weld", sw)
local lh = char:WaitForChild("LeftHand")

game:GetService("UserInputService").InputBegan:Connect(function(inputObject, gameProcessedEvent)
	if inputObject.KeyCode == Enum.KeyCode.Q then
		print("Q was pressed")
		w.Part0 = sw
		w.Part1 = lh
		wc.Enabled = false
		w.C0 = CFrame.new(0,0,0) * CFrame.Angles(math.rad(45), math.rad(0), math.rad(0))
	end
end)

The issue is that when you define "char" you did not capitalize "character", even though the valid property of the player is Character

Also, its generally better to use the local variables than the global ones in scripts

You can also alter the C0 property original vector (CFrame.new(0, 0, 0)) to make sure the offset is clearly visible, when you weld the part the way you have, the part is simply placed in the location of the player's hand with a rotation.

Part1 is generally the root part (left hand in this case), which is not meant to auto-move

In order for the player to be able to move, the "handle" should be unanchored.

10 comments

0

I probs should've explained it better, as basically I made a weld and welded a group to player this being a sheath with Handle being a mesh and part and being a sword. I am basically trying to make the Handle move from the other wield onto another wield so the player can hold the sword in their left hand.

0

I am sorry for not explaining much I didn't think it'd be an issue where it's probably with me having the sheath been previously wielded I also used a wield constraint just to make sure it doesn't move but after you click Q it disables it anyway. Also, thanks for telling about the other fixes as I never even noticed those but, yeah nothing worked so I will go a little more in depth basically

0

Or show u an example via video

0

you can show a vid if you think it helps. Based on what you said, it seems to me that you haven't destroyed the original weld, which is causing it to stay in place

0

Ohh

0

OOF

0

found out

0

I had a script that I had put in before that made all parts in the group welded so it wouldn't fall apart when unanchored but I also had weld constraints on every part so it triple welded everything wow, I spent like 5 hours on this little thing ;(. Anyway thanks bruh if you didn't help out with the other errors i'd still be confused and stressed thanks, man. Hopefully any others who ever come

0

by making such a dumb mistake they come across this question and answer, thanks again.

0

No problem, and yeah, I'm sure having three welds is a bit overkill! XD

This discussion is preserved as it was. New answers, comments, and votes are closed.