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

Welding to a Player?

I am trying to Weld a part to a player when they join the game, but the part just sits on the baseplate. I think on line 19 I have to put something after but I am confused.

local function weldBetween(a, b)
    print(a, b)
    local weld = Instance.new("Weld", a)
    weld.Part0 = a
    weld.Part1 = b
    weld.C0 = a.CFrame:inverse() * b.CFrame

 a.LocalTransparencyModifier = 0

    return weld
end

game.Players.PlayerAdded:connect(function(plr)
    plr.CharacterAdded:connect(function(chr)
    chr:WaitForChild( "Torso" )
        local part = Instance.new("Part", game.Workspace)
        part.Name = "Welded Part"
        part.Size = Vector3.new(2,2,2)
    part.CFrame = chr.Torso.CFrame

        local weld = weldBetween(part, chr.Torso)
    end)
end)


2 comments

0

Oh, I remember your old question. Maybe we can team create sometime? My main is EmeraldSlash

0

Maybe sometime.

2 answers

✓ Accepted answer

here is your weld function. A side note, this does not work if you dont follow the pattern, well it does but you may get out of the map.. or get stuck for a certain period of time

function weldToHuman(a,b) -- put person.torso as a and put object as b
	b.CFrame = a.CFrame-- * CFrame.new(0,0,0) place the values of where you want the part to be at through location x,y,z
	local  weld = Instance.new("Weld")
	weld.Part0 = a;
	weld.C0 = a.CFrame:inverse()
	weld.Part1 = b;
	weld.C1 = b.CFrame:inverse()
	weld.Parent = a;	
	return weld;
end
game.Players.PlayerAdded:connect(function(player)
	print(player.Name .. " Welcome");
	player.CharacterAdded:connect(function(character)
		print(character.Name .. "  character")
		wait(2);-- waiting until character loads as  you become a player before a character
		weldToHuman(character.Torso,Instance.new("Part",game.Workspace))-- always have character parts first in this code
	end)
end)
print("loaded welding")

This does work. I had to understand how two events worked together, so thats why you see print statements. Anyways. Welcome.

1 comment

0

Thank you so much! I thought no one was going to fix this!

Wild guess, but try switching part with torso on 21. line.

When welding, I always follow logic, that part0 is the static part and part1 is the one being moved around. So far hasn't let me down.

1 comment

0

Leet, answered gave an answer before ya.

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