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

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

Asked by
AizakkuZ 226 Moderation Voter
5 years ago

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)
0
You're Dumb User#24403 69 — 5y
0
lmaoo AizakkuZ 226 — 5y
0
Make sure your part is not Anchored. sleazel 1287 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago
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.

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. AizakkuZ 226 — 5y
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 AizakkuZ 226 — 5y
0
Or show u an example via video AizakkuZ 226 — 5y
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 SerpentineKing 3885 — 5y
View all comments (6 more)
0
Ohh AizakkuZ 226 — 5y
0
OOF AizakkuZ 226 — 5y
0
found out AizakkuZ 226 — 5y
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 AizakkuZ 226 — 5y
0
by making such a dumb mistake they come across this question and answer, thanks again. AizakkuZ 226 — 5y
0
No problem, and yeah, I'm sure having three welds is a bit overkill! XD SerpentineKing 3885 — 5y
Ad
Log in to vote
0
Answered by
AizakkuZ 226 Moderation Voter
5 years ago

https://youtu.be/W8cTer8lO2A

Answer this question