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 7 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.

01script.Parent.Touched:connect(function(hit)
02 humanoid = hit.Parent:findFirstChild("Humanoid")
03 if humanoid then
04  head = hit.Parent.Torso
05  script.Parent.CFrame = head.CFrame * CFrame.new(-0.8,1,-0.0008)
06  weld = Instance.new ("Weld")
07  weld.Part0 = head
08  weld.C0 = head.CFrame:inverse()
09  weld.Part1 = script.Parent
10  weld.C1 = script.Parent.CFrame:inverse()
11  weld.Parent = script.Parent 
12  script.Parent.Anchored = false
13 end
14end)

1 answer

Log in to vote
0
Answered by 7 years ago

So basically it's pretty simple. Instead of:

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

You would put:

1game.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.

1head = player.Character:FindFirstChild("Head")
2weld.Part0 = head
3weld.C0 = head.CFrame:inverse()
4weld.Part1 = script.Parent
5weld.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 — 7y
Ad

Answer this question