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

Why won't this part weld to my character's torso on respawn?

I am trying to make a part be welded to any character that joins the game and whenever a character respawns, but it just quite isn't working. Got an error that keeps saying "Torso is not a valid member of player" but i don't really don't know how to define the local player that spawned, if that makes any sense.

game.Players.PlayerAdded:connect(function(player)
	player.CharacterAdded:connect(function(character)
		print("Lol, I respawned")
		local part = Instance.new("Part")
		part.Shape = Enum.PartType.Block
		part.Name = "Assassin Block"
		part.Transparency = 0
		part.Size = Vector3.new(2,1,2)		
		part.CanCollide = false
		
		local weld = Instance.new("Weld", part)
		weld.Part0 = character.Torso
		weld.Part1 = part
		weld.C1 = CFrame.new(0,0,0)
		
		part.Parent = game.Workspace
		part.Position = player.Torso.Position
	end)
end)

2 comments

0

player does not hold the characters model, character is the players model

0

I'm no longer getting the error, but the block still doesn't spawn :/

1 answer

✓ Accepted answer

You have to make the script wait for your part to be created.

game.Players.PlayerAdded:connect(function(player)
    player.CharacterAdded:connect(function(character)
        print("Lol, I respawned")
        local part = Instance.new("Part",game.Workspace)
        part.Shape = Enum.PartType.Block
        part.Name = "AssassinBlock"
        part.Size = Vector3.new(2,1,2)      
        part.CanCollide = false
		repeat wait() until game.Workspace.AssassinBlock ~= nil
        local weld = Instance.new("Weld",game.Workspace.AssassinBlock)
        weld.Part0 = character.Torso
        weld.Part1 = part
        weld.C1 = CFrame.new(0,0,0)
        part.Position = character.Torso.Position
    end)
end)

1 comment

0

Thanks! it works now. :)

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