Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Welding a hat onto a player upon join?

A hat gets welded onto the player if the player touches the hat for this script. This works.

function onTouch(hit)
	if hit.Parent:findFirstChild("Humanoid") and script.On.Value == false then
	script.On.Value = true
	script.Parent.Anchored = true	
	local arm = hit.Parent:FindFirstChild("Head")
	local rift = script.Parent.Parent:clone()
	rift.Parent = hit.Parent
	rift.Head.Script:remove()
	rift.Head.Anchored = false
	local w = Instance.new("Weld")
	w.Name = "PB"
	w.Parent = hit.Parent:FindFirstChild("Torso")
	w.Part0 = rift.Head
	w.Part1 = arm
	wait(1)
	script.On.Value = false 
	end
end
script.Parent.Touched:connect(onTouch)

I want to change it so this hat will weld onto the players character upon join. By the way, I made a new script for this and the location is different than the one on the top so it will look different. This did not work at all and had no errors.

game.Players.PlayerAdded:connect(function(player)
	player.CharacterAdded:connect(function(character)
		wait()
		script.Parent.Head.Anchored = true
		local arm = player:FindFirstChild("Head")
		local rift = script.Parent:Clone()
		rift.Parent = player
		rift.Head.Anchored = false
		local w = Instance.new("Weld")
		w.Name = "PB"
		w.Parent = player:FindFirstChild("Torso")
		w.Part0 = rift.Head
		w.Part1 = arm
	end)
end)

1 answer

✓ Accepted answer
game.Players.PlayerAdded:connect(function(player)
    player.CharacterAdded:connect(function(character)
        -- wait() You don't need this, it'll trigger when appropriate. 
        script.Parent.Head.Anchored = true
        local arm = player:FindFirstChild("Head") -- You mean character?
        local rift = script.Parent:Clone()
        rift.Parent = player -- You mean character? Because 'player' doesn't have a Head.
        rift.Head.Anchored = false
        local w = Instance.new("Weld")
        w.Name = "PB"
        w.Parent = player:FindFirstChild("Torso") -- Again, do you mean character?
        w.Part0 = rift.Head
        w.Part1 = arm
    end)
end)

** So your issue was that you mixed up player and character. **

*Otherwise, I -think- it should work.

This discussion is preserved as it was. New answers, comments, and votes are closed.