Trying to change text on an part when its shot

I wanna make a target, when you shoot it the text changes to the amount of health left after you shot/hit it.
robloxapp-20220313-1452337
Is there any way i can do this?

1 Like

You can first detect how many times the target was shot, then multiply it with the damage per shot and then subtract it from the full health of the target.

As explained in the post above you have something to detect shots, subtract it by the Hp of your target and change the textlabel’s text to whatever number you got

I tried using this script:

function Track(Humanoid)
	local Last =script.Parent.Parent.Humanoid.Health
	local function HealthChanged(Left)
				print("work")
				local TextLabeled = script.Parent.SurfaceGui.TextLabel:Clone()
				TextLabeled.Text = math.floor('-'..Last - Left)

	end
	Humanoid.HealthChanged:connect(HealthChanged)
end

script.Parent.Touched:Connect(Track)

Doesnt print out work , plus no errors. Anything wrong?

When you raycast for your gun, is your ray actually firing the .Touched event?

how do i check it? kinda new to this stuff

If your ray is casted by the server and hit hits something you could fire a bindable event so that another script that handles your targets will subtract its health value by how much damage has been sent through the bindable event