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

Welded Part is Invisible?

I am trying to weld a part to a player when they join the game, but it only happens to one person. Unless starting servers from roblox studio is messed up, because I put 2 players in, and on Player 2's screen, Player 1 has the part welded to him, but Player 2 doesn't. Then if I go onto Player 1's screen, none of them have it. Plus I look at the server window and in the output it says "An error occurred" and both of the players have it on. Here is the script:

local function weldBetween(a, b)
print(a, b)
    local weld = Instance.new("ManualWeld", a)
    weld.Part0 = a
    weld.Part1 = b
    weld.C0 = b.CFrame:inverse() * b.CFrame
a.LocalTransparencyModifier = 0
	a.Parent = b
    return weld
end

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

1 answer

I'm not sure what exactly is wrong, but I spotted few mistakes. It should work fine once fixed.

local function weldBetween(a, b)
    print(a, b)
    -- Why use manualWeld? Just use regular one
    local weld = Instance.new("Weld", a)
    weld.Part0 = a
    weld.Part1 = b
    -- You inversed b cframe and multiplied with b cframe, which would result into empty CFrame
    -- instead, inverse origin and multiply with other cframe
    weld.C0 = a.CFrame:inverse() * b.CFrame

    -- Not sure where you were going with these lines, especially parenting a part to b
    -- a.LocalTransparencyModifier = 0
    -- a.Parent = b
    return weld
end
	 
game.Players.PlayerAdded:connect(function(plr)
    plr.CharacterAdded:connect(function(chr)
	-- Wait for torso to properly get created
	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 -- Position it somewhere, or else it will spawn at 0,0,0 and weld to player from that distance

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

4 comments

0

I tried it and it didn't work. The part just sits on the baseplate

0

It would weld the part based on where it was when player spawned. Also, might need to add wait for child there.

0

Where do I need to put waitforchild?

0

I already updated the script, it wait's for torso.

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