Script doesn't work

Hello , I want to make text that will show health of model / pillows but you can see that doesn’t work.
here is script

local health = script.Parent.Parent.Parent.Health
local tyman = script.Parent

	tyman.Text = "Health:"..health.Value

you can see here my explorer
image
Thank you for help !

We can’t see anything actually. Mind sending a video or something?

(Also, I would use a local script, as it replicates to the client)

1 Like

wrong it only run’s once

he should change the code to this

local health = script.Parent.Parent.Parent.Health
local tyman = script.Parent
while wait() do
    tyman.Text = "Health:"..health.Value
end

I would suggest using .Changed or :GetPropertyChangedSignal, and not a wait() loop.

Personally, anyway.

its the best answer if you are lazy to write those

local health = script.Parent.Parent.Parent.Health
local tyman = script.Parent

health.Changed:Connect(function()
	tyman.Text = "Health: "..health.Value
end)

This will fire every time the health is changed, assuming you’re changing the health, it should work.

2 Likes

Its not necessarily the most efficient, either.

in this context using wait() can be understandable but using .Changed is probably the most efficient, like you said. It just updates every second, but the .Changed runs everytime the value is changed.

3 Likes

https://gyazo.com/f2643c0904de365f4db01c24a0695560 here the video about problem , I have intvalue named Health and the health becomes lower every punch but as you can see it doesn’t show reall health

Can you show where you stored the IntValue?

I’v shown before my explorer part so you can see it there . Or maybe I don’t understand what does mean stored

local Health = script.Parent.Parent.Parent.Health
local tyman = script.Parent

Health:GetPropertyChangedSignal("Value"):Connect(function()
   tyman.Text = "Health: "..Health.Value
end)

For it to change the text, you would want to listen if the value has changed. Using a while true do loop is not really efficient and can result in less performance, so we just need to get a signal if the value has changed.

1 Like

must script be local or not ? Because I have local script and it still doesn’t work

If you want it to update it to every player, use a server script. Otherwise, use a local script.

1 Like