Why doesnt this work?

so this code is supposed to weld the armor piece to the bodypart BUT if the player dies i cant equip a new piece of armor? did i do something wrong?

local Tool = script.Parent
local Handle = Tool.Handle
local HealthValue = Tool.Health.Value

local Sound = Tool.Sound

game.Players.PlayerAdded:Connect(function(plr)
	local Character = plr.Character or plr.CharacterAdded:Wait()
	local Torso = Character:WaitForChild("UpperTorso")
	
	local Humanoid = Character:WaitForChild("Humanoid")
	
	Tool.Activated:Connect(function()
		local Helmet = Character:FindFirstChild("Helmet")
		if Helmet then
			Helmet:Destroy()
			Humanoid.MaxHealth -= HealthValue
			Sound:Play()
			
			
		else
			local NewHelmet = Handle:Clone()
			NewHelmet.Name = "Helmet"
			NewHelmet.Parent = Torso
			Sound:Play()

			Humanoid.MaxHealth += HealthValue

			local weld = Instance.new("Weld")
			weld.Part0 = NewHelmet
			weld.Part1 = Torso
			weld.C1 = CFrame.new(0, -0.2, 0)
			weld.C0 = weld.C0 * CFrame.Angles(0, math.rad(-90), 1.6) * CFrame.Angles(math.rad(90), 0, 0)
			weld.Parent = NewHelmet
		
		end
	end)
end)

you should try putting the activated function into the actual tool instead. but if you want the helmet to be on the character’s head (assuming you’re not using a startercharacter) every time (even when they respawn), then use CharacterAdded

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.