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

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

Asked by 2 years ago
Edited 2 years 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 2658 Moderation Voter Community Moderator
2 years 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 2 years 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