Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why does this gui crash studios?

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

2 answers

✓ Accepted answer

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)

2 comments

0

Why are you using GetService? They conveniently made it so that you could access stuff in Workspace simply by putting "workspace.x".

0

Also this would not contiously update the text like a While loop as im pretty sure he was trying to do.

This discussion is preserved as it was. New answers, comments, and votes are closed.