local HealthbarFrame = script.Parent:WaitForChild("HealthbarFrame")
local Holder = HealthbarFrame:WaitForChild("Holder")
local Background = HealthbarFrame:WaitForChild("Background")
local Player = game.Players.LocalPlayer
local Character = Player.Character
local TweenService = game:GetService("TweenService")
local RunService = game:GetService("RunService")
local OldTween = nil
repeat wait() until Character:FindFirstChild("Humanoid")
local Humanoid = Character:FindFirstChild("Humanoid")
local DotSize = Holder.Left.AbsoluteSize.X
Holder.Center.Size = UDim2.new(1,-DotSize,1,0)
Background.Center.Size = UDim2.new(1,-DotSize,1,0)
Humanoid.Changed:Connect(function(Property)
if Property == "Health" then
local MaxHealth = Humanoid.MaxHealth
local Health = Humanoid.Health
if OldTween ~= nil then
OldTween:Cancel()
end
OldTween = TweenService:Create(Holder,TweenInfo.new(.5,Enum.EasingStyle.Back),{Size = UDim2.new(Health/MaxHealth,0,1,0)})
OldTween:Play()
end
end)
Here is the mob damage script. I put this in the upper torso
script.Parent.Touched:Connect(function(part)
if part.Parent:FindFirstChild("Humanoid") then
part.Parent.Humanoid:TakeDamage(1)
end
end)
In the mob you maybe should do that mob damages the player humanoid with humanoid:TakeDamage(10) and mob change health in gui. Hope this helps.
Edit: In health bar you should do local health = Instance.new("IntValue")
health.Name = "Health"
health.Value = humanoid.Health
health.Parent = healthgui
So this will make an actual value. And in mob you shoul add
local plr = game.Players:GetPlayerFromCharacter(part.Parent) local h = plr:FindFirstChild("PlayerGui).ScreenGui.healthbar.Health h.Value = h.Value - 10
If this does not work tell me and i will try to fix it.
Edit 2: Insted humanoid.Changed do humanoid.HealthChanged, i think this will work.