enemy = script.Parent.Parent.Parent.Parent.Parent.Parent -- Enemy
hum = enemy.Humanoid -- Enemy Humanoid
local function HealthFunc()
script.Parent.Size = UDim2.new(0, hum.Health * 150/hum.MaxHealth, 0, 50) -- Scale Gui for the Bar
script.Parent.Stat.Text = tostring(hum.Health).."/"..hum.MaxHealth -- Change the Text
if hum.Health <= 0 then
enemy:Destroy() -- Destroy Enemy if Health is 0 or less (If it's Dead)
end
if enemy.OV.Value ~= nil then
hum:MoveTo(enemy.OV.Value.HumanoidRootPart.Position)
hum.MoveToFinished:Wait()
print(enemy.OV.Value.HumanoidRootPart.Position)
end
end
HealthFunc() -- Reset GUI when Enemy Spawned
hum.HealthChanged:Connect(HealthFunc) -- Trigger Function when Health of Enemy is Changed
The script tries to follow the player based on an object value.
if humanoid.Parent:FindFirstChild("OV") == nil then
local objVal = Instance.new("ObjectValue")
objVal.Name = "OV"
objVal.Parent = humanoid.Parent
objVal.Value = Player.Character
else
humanoid.Parent:FindFirstChild("OV").Value = Player.Character
end
humanoid:TakeDamage(Damage)
The object value is placed like this in the sword script and the enemy takes the position from the value of the object value.
No errors, it just doesn't work.
