Issues with Roblox Studio Not Functioning

I’ve decided to get back into studio to create a fun little project that I had in mind, but I have been consistently having this issue where my script exhibits different behaviors every time I run it. I’m not sure whether or not the code that I made is the problem or if it’s my studio that’s acting up. I attached the only bit of code in the entire game so far, albeit coarse, but I can’t really find a discernable problem with it.

local loadingScreenGUI = game.StarterGui.ScreenGui;

-- For loops to increment the time textLabel
for i = 1, 10, 1 do
	if (i % 2 == 0) then
		loadingScreenGUI["Loading Text"].Text = "Loading.. (" .. i .. ")";
		wait(1);
	elseif (i % 2 == 1) then
		loadingScreenGUI["Loading Text"].Text = "Loading... (" .. i .. ")";
		wait(1);
	end
end

-- Rudimentary loops that makes the game fade away
for i = 0.01, 1, 0.01 do
	loadingScreenGUI["Loading Text"].TextTransparency = i;
	wait(0.5);
end
game.SoundService.Pop:Play();

for i = 0.01, 1, 0.01 do
	loadingScreenGUI.Frame.BackgroundTransparency = i;
	wait(0.5);
end
game.SoundService.Pop:Play();

If there’s even a problem with the syntax that I’m using please don’t feel hesitant to let me know! I was preoccupied with Java for the longest time and as far as I know semi-colons are only a stylistic feature.

1 Like

Hi! My subjective opinion is that in this situation it is better to use the Tween Service if you want to make transitions, animations, downloads in the player interface locally. For example:


local loadingScreenGUI = game.StarterGui.ScreenGui
local TweenService = game:GetService("TweenService")

-- Function to create a new tween
local function createTween(object, property, endValue, duration)
    local tweenInfo = TweenInfo.new(duration)
    local tween = TweenService:Create(object, tweenInfo, { [property] = endValue })
    return tween
end

-- For loop to increment the time textLabel
for i = 1, 10, 1 do
    local newText = (i % 2 == 0) and "Loading.. (" .. i .. ")" or "Loading... (" .. i .. ")"
    local textLabel = loadingScreenGUI["Loading Text"]
    
    -- Create a tween to smoothly change the text
    local tween = createTween(textLabel, "Text", newText, 1)
    tween:Play()
    
    -- Wait for the tween to finish
    tween.Completed:Wait()
end
1 Like

Also, you should create a local script by placing it in the ScreenGui of your game and instead of the variable “game.StarterGui.ScreenGui” specify “script.Parent” in the 1st line

1 Like

Hello!

If the script is local, you might also want to access the GUI a different way. Whenever the game runs, StarterGUI is destroyed and all of its children and parented to the PlayerGUI, and this can cause an error. So first you would need to access the player a s then wait for a child named PlayerGUI. Then find the first child named whatever your GUI is.

Hope this helps! :slight_smile:

what is this unoptimized thing?
use tweenservice and try to avoid loops unless necessary.

like so

local player = game.Players.LocalPlayer
local screenUI = player.PlayerGui.ScreenGui
local loading = screenUI["Loading Text"]--store in var to reduce cpu reads

local tweenService = game:GetService("TweenService")--use tweenservice to remove redunant loops
local info = TweenInfo.new(1)

local pop = game.SoundService:WaitForChild("Pop")--store in var to reduce cpu reads

local textTween = tweenService:Create(loading, info, {TextTransparency = 1})
local backTween = tweenService:Create(screenUI.Frame, info, {BackgroundTransparency = 1})

for i = 1, 10, 1 do
   loading.Text = i % 2 == 0 and string.format("Loading.. (%d)", i) or string.format("Loading... (%d)", i)
--symbols are %s = strings, %d = whole nums, %.nf = any float rounded to n decimal place. and more
--these come from the c format function in printf() and c++ has this too.
end

textTween:Play()--plays tween
textTween.Completed:Wait()--waits for it to finish

pop:Play()--repeat

backTween:Play()
backTween.Completed:Wait()

pop:Play()

edit: like the others said, put it in the screen gui, that way you can replace:

local screenUI = player.PlayerGui.ScreenGui
--with
local screenUI = script.Parent

that’s not how that works but ok.
you can tween maxvisiblegraphemes to the length of the string but that wouldn’t really look nice.
also he did not ask for this.

Instead of text animating that way, use a typewriter effect function.
this doesn’t use tweenservice, but it gives you more control:

local function TypeWrite(label: TextLabel, msg: string, delay: number)
   for i=0, i<#msg do
      label.Text = string.sub(msg, 1, i)
      task.wait(delay)
   end
end

now you can do something like:

TypeWrite(mylabel, "hello", 0.01)