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

How do I add this brick to Every players character?

Asked by 9 years ago

This is what I have but it there's a problem somewhere

Part = script.Parent.Vest
players = game.Players:GetChildren() 

    for i = 1,#players do 

Part:clone(i)
Part.Parent = players[i].Character

    end
0
Hello? If it helps, accept my answer. Thank you. EzraNehemiah_TF2 3552 — 9y

1 answer

Log in to vote
2
Answered by 9 years ago

I am writing this answer, by the time I post it there might be another answer. If there is, PLEASE look at all the answers since this one took over 30 minutes to write.


  1. We need to get the player through PlayerAdded
  2. We need to get the character through CharacterAdded
  3. We need to clone the model and teleport it to the correct position
  4. We might have to weld it!
  5. I could teach your what the died event is!


PlayerAdded

This event runs when a player joins a game.

game:GetService("Players").PlayerAdded:connect(function(player)
    print(player.Name.." has joined the game!")
end)

Fun Facts about PlayerAdded

  1. It's counterpart is PlayerRemoving, not PlayerLeaving.
  2. When using PlayerRemoving to save Datastores, make sure to use the closing event.


CharacterAdded

The event fires when a player's character is created, whether it's from joining a game or respawning.

game:GetService("Players").PlayerAdded:connect(function(player)
    player.CharacterAdded:connect(function(character)
        print(player.Name.." spawned.")
    end)
end)

Fun Facts about CharacterAdded

  1. It fires when a character spawns, even after dieing, so incase you die with a vest, It will still stay on.


Teleporting Models

There are 2 ways of teleporting models. 1. MoveTo() 2. SetPrimaryPartCFrame()


MoveTo

MoveTo needs a vector3 value to be teleported. The center of the model will be teleported to the position.

workspace.Model:MoveTo(workspace.Player.Torso.Position)

SetPrimaryPartCFrame

It may seem annoying but! It's useful for changing ROTATION, using CFrame.Angles. SetPrimaryPartCFrame needs a CFrame value and the model will be teleported. The primary part will be teleported to the location, and the rest of the model will follow. It will only work with a primary part.

workspace.Model:SetPrimaryPartCFrame(workspace.Player.Torso.CFrame)

Fun Facts about Teleporting Models

  1. If you use MoveTo on a model it teleports the model. If you use it on a humanoid, the character WALKS to the position. Crazy huh?!


Welding

Welding makes parts stick together like Lego Bricks(I do not own the Lego™, all rights go to the Lego company) you can weld parts that are not even touching! You can break welds using BreakJoints() and make welds by using MakeJoints().


Fun Facts about Welding

  1. They have a wiki page ALL about welding, it's on the front page(as of May 2015).


Died event

This event if optional. It runs whenever a humanoid's health reaches 0, either by disconnecting the head and torso or by damage.

game:GetService("Players").PlayerAdded:connect(function(player)
    player.CharacterAdded:connect(function(character)
        character.Humanoid.Died:connect(function()
            print(player.Name" has died!")
        end)
    end)
end)

Fun Facts about Died

  1. You can use this event to make a leaderboard about deaths and kills using the died event!



Final Product

local vest = script.Parent.Vest:clone()

game:GetService("Players").PlayerAdded:connect(function(player)
    player.CharacterAdded:connect(function(character)
        vest.Parent = character
        vest:MoveTo(character.Torso.Position) --Using moveto incase you don't have a primary part
        character:MakeJoints() --Make sure that the vest has welds in it.
    end)
end)




Hope this helps!

Ad

Answer this question