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

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

Asked by 8 years ago

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)
0
player does not hold the characters model, character is the players model User#5423 17 — 8y
0
I'm no longer getting the error, but the block still doesn't spawn :/ Sparkflyer34 40 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

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)

0
Thanks! it works now. :) Sparkflyer34 40 — 8y
Ad

Answer this question