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

Help With Script That Weld's To Player When They Connect?

Asked by 6 years ago

Hello can someone help me with this script my friend gave me? its a weld script, that when you touch the part it welds to your torso. But it only works when you touch it can someone help me do it when someone connects to the game? thanks.

I'm really new to lua and just needed that script to test out my gui i made.

script.Parent.Touched:connect(function(hit)
 humanoid = hit.Parent:findFirstChild("Humanoid")
 if humanoid then
  head = hit.Parent.Torso
  script.Parent.CFrame = head.CFrame * CFrame.new(-0.8,1,-0.0008)
  weld = Instance.new ("Weld")
  weld.Part0 = head
  weld.C0 = head.CFrame:inverse()
  weld.Part1 = script.Parent
  weld.C1 = script.Parent.CFrame:inverse()
  weld.Parent = script.Parent  
  script.Parent.Anchored = false
 end 
end)

1 answer

Log in to vote
0
Answered by 6 years ago

So basically it's pretty simple. Instead of:

script.Parent.Touched:connect(function(hit)

You would put:

game.Players.PlayerAdded:connect(function(player)

Then you would have to specify the parts of the player's character that you'd want to weld the parts to. So if you wanted the character's Head then you would do.

head = player.Character:FindFirstChild("Head")
weld.Part0 = head
weld.C0 = head.CFrame:inverse()
weld.Part1 = script.Parent
weld.C1 = script.Parent.CFrame:inverse()

Or if it were the Torso you wanted to weld to just change ("Head") to ("Torso"). Also if you're looking into working with R15, the "Torso" doesn't exist on an R15 character as a heads up. You should use "HumanoidRootPart" instead in that case.

0
Thank you so much dude you help me alot ;) JuuzouBlitz 75 — 6y
Ad

Answer this question