How would i make this work

Hello fellow devs how would I make this system someone has scripted for my work when the vest is in the player’s character because it only works when touched?

local equipped = false
local rate = 200
local walk = 13
local jump = 35

handle.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild(“Humanoid”) and equipped == false then
vest.Parent = hit.Parent
hit.Parent.Humanoid.MaxHealth = rate
hit.Parent.Humanoid.Health = rate
hit.Parent.Humanoid.JumpPower = jump
hit.Parent.Humanoid.WalkSpeed = walk
equipped = true
end
end)

More like:

local equipped = false
local rate = 200
local walk = 13
local jump = 35

handle.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") and equipped == false then
		vest.Parent = hit.Parent
		hit.Parent.Humanoid.MaxHealth = rate
		hit.Parent.Humanoid.Health = rate
		hit.Parent.Humanoid.JumpPower = jump
		hit.Parent.Humanoid.WalkSpeed = walk
		equipped = true
	end
end)

BUT there’s 2 warnings.

That script uses the Touched event to detect when a player touches the vest. If so, it parents the vest to the character. If you want players to spawn with the vest automatically, you can make use of the CharacterAdded event. Basically, whenever a character loads in, parent the vest to their HRP.

player.CharacterAdded:Connect(function(char)
    local HRP = char:WaitForChild("HumanoidRootPart")
    local cloneVest = game.ServerStorage:WaitForChild("Vest"):Clone()
    cloneVest.Parent = HRP
end

You might want to weld the vest to the HRP, otherwise it’ll fall into the void immediately.

1 Like