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

healthbar I made lowers when i lower health through explorer but not when hit by mob.?

Asked by 5 years ago
Edited 5 years ago
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)

0
Maybe the mob is damaging the player on the client? Show us the mob script too Ankur_007 290 — 5y
0
If the tween was actually working through changing properties, it's probably a problem with the mob script. Your mob may not have a humanoid. Psudar 882 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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.

0
Im very new to scripting, but i think i already have that. I posted the script if you wanna take a look, Thanks! odinbreaker -5 — 5y
0
Take away the ' and change Healt to Health Ryanrecker2 2 — 5y
Ad

Answer this question