Sword not doing damage to a brick with a humanoid + not updating text

The textlabel isn’t being updated like it should and it isn’t taking any damage either, even though I added a humanoid. Can someone help me? The scripts are:

update text label script:

local helth = script.Parent
local bricc = workspace.brickgod
local human = bricc.Humanoid

while true do
helth.Text = "bricc helth: " ..human.Health
wait(5)
end

damage script:

script.Parent.Touched:Connect(function(hit)
	local humanoid = hit.Parent:FindFirstChildWhichIsA('Humanoid')
	if humanoid then
		humanoid:TakeDamage(10) 
	end
end)
2 Likes

Ok first of all, is the script a LocalScript? If so, I will check the code in case there is any error.

1 Like

No, which script is meant to be a localscript?

1 Like

The script inside the GUI. GUIs use LocalScripts to modify themselves.
Remember that LocalScripts affects the Client not the Server. That’s the reason, because GUIs work with a single client not with the whole server.

1 Like

Done, but it still wont update it and the health doesn’t change so there’s something wrong with the damage script

The text now changes though.

1 Like

Maybe this?

script.Parent.Touched:Connect(function(hit)
	-- local humanoid = hit.Parent:FindFirstChildWhichIsA('Humanoid') Instead of this try with FindFirstChild
    local humanoid = hit.Parent:FindFirstChild("Humanoid")
	if humanoid and humanoid.Health ~= 0 then
		humanoid:TakeDamage(10) 
	end
end)
1 Like

Still damages things but it doesn’t work.

1 Like

if humanoid and humanoid.Health ~= 0 then

Do you have the 0 instead of “nil”? Because I made a small mistake and maybe you copied it wrong.

Yeah but that doesn’t change the fact that it doesn’t damage it.

1 Like

I have the solution! The Humanoid Must be inside a model. Put the Part and the Humanoid in the same model.
Hope this works, I am not 100% sure.

2 Likes

Would the humanoid be inside the part still or would it be just inside the model?

1 Like

Inside the model, if this doesn’t work I will try to remake the scripts.

It works now! Thank you so much!

No problem! I am glad it worked! Make sure you make that answer the solution.

Also, is there a way to make that a bar? Like instead of using text you can make it like a progress bar but it goes down.

You could insert a progress bar, insert a script inside it. And in the script you divide the health by maxHealth and round it up.

I’ve never used it so I do not understand a word about what you’re saying.

First, you create a progress bar. Then you do some math:

local frame = script.Parent
local bricc = workspace.brickgod
local human = bricc.Humanoid

while true do
   frame.Size = UDim2.new(math.floor((bricc.Humanoid.Health) / (bricc.Humanoid.MaxHealth)),0,1,0)
end

That would be a health bar basically, YT is full of tutorials but I can show you a small script here.

A useful tutorial.

local HPBar = script.Parent.Parent:FindFirstChild("HPBarName")
local Brick = workspace:FindFirstChild("brickgod")
local Human = Brick:FindFirstChild("Humanoid")

Human.HealthChanged:Connect(function()
     local Percent = Human.Health / Human.MaxHealth * HPBar.Size.X.Offset
     HPBar.Size = Udim2.new(0, Percent, 0, HPBar.Size.Y.Offset)
end)
1 Like

You will have to make your own HealthBar Frame

1 Like