I made this script, and it crashes my roblox studios! I'm not sure why.. Please let me know!
while true do
local HealthNum = game.workspace.Cake.Humanoid.Health
script.Parent.Text = HealthNum.."/100"
end
I made this script, and it crashes my roblox studios! I'm not sure why.. Please let me know!
while true do
local HealthNum = game.workspace.Cake.Humanoid.Health
script.Parent.Text = HealthNum.."/100"
end
Simple, the while true do loop is attempting to execute without any delay time. Basically it's trying to run multiple operations at once infinitely, and that causes roblox crashes. Obviously the simplest way to fix it is by putting a wait(Seconds) somewhere in the loop, preferably at the beginning or at the end, like so:
while true do
local HealthNum = game.workspace.Cake.Humanoid.Health
script.Parent.Text = HealthNum.."/100"
wait() --This makes the loop wait 1/30th of a second
end
Hope this helped!
A smarter way to approach this would be to do the following:
Humanoid = game:GetService("Workspace"):WaitForChild("Cake").Humanoid
Humanoid.Changed:connect(function()
script.Parent.Text = Humanoid.Health.."/100"
end)
This discussion is preserved as it was. New answers, comments, and votes are closed.
2 comments
Why are you using GetService? They conveniently made it so that you could access stuff in Workspace simply by putting "workspace.x".
Also this would not contiously update the text like a While loop as im pretty sure he was trying to do.