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

How do I make a PlayerJoin weld?

Asked by 5 years ago
Edited 5 years ago

Okay so I am making a vest by welding it through scripting so when they touch a part it welds, but now I want it to automatically weld it when they first join the game and they can only get it once. I have tried to use a PlayerAdded function but it didn't work. here is my code [ `

function onTouched(hit)

if hit.Parent:findFirstChild("Humanoid") ~= nil and hit.Parent:findFirstChild("[Vest") == nil then

local g = script.Parent.Parent["Vest"]:clone()

g.Parent = hit.Parent

local Y = Instance.new("Weld")

Y.Part0 = hit.Parent.Torso

Y.Part1 = g.Middle

g.Middle.Anchored = false

Y.Parent = hit.Parent.Torso

end



end



script.Parent.Touched:connect(onTouched)

`]

Help?

1 answer

Log in to vote
0
Answered by
Divistern 127
5 years ago

If you want to know how to weld the vest to a player that has joined, It's easy and can be done just simply by Putting the following code in a Script

local vest = script.Parent.Vest
game.Players.PlayerAdded:Connect(function(plr)
    plr.CharacterAdded:Connect(function(char)
        local TO = char:FindFirstChild("Torso")
        local VestCLONE = vest:Clone()
        vestCLONE.Parent = char
        local VWeld = Instance.new("Weld")
        VWeld.Parent = vestCLONE
        VWeld.Part0 = TO
        VWeld.Part1 = vestCLONE
    end)
end)

If you want to use it while touching a Part then just put the following Code in a Script that is a child of the Part to be Touched

local part = script.Parent
local vest = script.Parent.Vest
part.Touched:Connect(function(hitter)
    --Preventing Duplicating way too much vests
    if hitter.Parent:FindFirstChild("Vest") then
        return
    end
    --Checking if is a player's character
    if hitter.Parent:FindFirstChild("Humanoid") then
        local char = hitter.Parent
        local TO = char.Torso
        local vestCopy = vest:Clone()
        vestCopy.Parent = char
        local VWeld = Instance.new("Weld")
        VWeld.Parent = vestCopy
        VWeld.Part0 = TO
        VWeld.Part1 = vestCopy
    end
end)

Results: !Results of all vest Givers

Ad

Answer this question