Ad
Log in to vote
1

my script wont work ive been searching on YouTube but nothing popped up?

Asked by 2 days ago
Edited 2 days ago

what is wrong with this function

armor.Touched:Connect(function(touchedPart) local humanoid = touchedPart.Parent:FindFirstChild("Humanoid") if humanoid then humanoid.MaxHealth = 200 armor.Position = Vector3.new(torso.Position) end end)

2 answers

Log in to vote
0
Answered by
Xapelize 1835 Moderation Voter
2 days ago
armor.Touched:Connect(function(touchedPart) 
    local humanoid = touchedPart.Parent:FindFirstChild("Humanoid")
    if humanoid then 
        humanoid.MaxHealth = 200 
        humanoid.Health = 200 -- set it to 200 because if max health changes health does not change, do this before setting MaxHealth
        armor.Position = torso.Position -- do this because it still return Vector3 value 
    end 
end)
Ad
Log in to vote
0
Answered by
FrindowYT 283 Moderation Voter
2 days ago

Instead of using Vector3.new just set it to the torso position directly like this:

    armor.Touched:Connect(function(touchedPart)
        local humanoid = touchedPart.Parent:FindFirstChild("Humanoid")
        if humanoid then
            humanoid.MaxHealth = 200
            humanoid.Health = 200
            armor.Position = torso.Position -- Replace Vector3 with this
        end
    end)

Answer this question