Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why does this script in ScreenGUI not want to work in online mode?

Asked by 8 years ago

Why does this work in studio but not in online mode?

I have made a pokemon-like gui where is individually types out the letters and plays a sound. Here are all the things I have in it:

Local Script - Named Local Script

local gui = script.Parent
local tick = script.Parent.Tick
local text = script.Parent.TextLabel
if game.Players.LocalPlayer.Name ~= "Player" then
end
if text.Visible == true then
function mes(text1, text2, wait1)
    for i=1,string.len(text2) do
        if string.sub(text2,i,i)==" " then
            text1.Text=string.sub(text2,1,i)
            i=i+1
            wait(wait1)
        else
            text1.Text=string.sub(text2,1,i)
            i=i+1
            tick:Play()
            wait(wait1)
        end
    end
end

text.Text = ""
mes(text, "Welcome to Bakery Tycoon! I hope that you have a wonderful time making some nice pastry products. Maybe you'll even become Santa's little elf or a mini Santa. Who knows? Go explore and find out!", 0.08)

end

Audio - Named Tick SoundID: rbxassetid://140910211 RollOffMode: Inverse PlaybackSpeed: 3.5 EmitterSize: 10 -- Should be essential properties there ^

Text Label - Named TextLabel

This is all inside a ScreenGui and works in studio but not in online mode. It says Tick is not a valid member of ScreenGui Line 3

Here is the place if you want to see the error code yourself

0
I'm pretty sure 'Tick' has just not loaded yet. Try using WaitForChild. Goulstem 8144 — 8y
0
Ok thanks TheUniPiggy 77 — 8y
0
And if you wanna clean up the 'mes' function.. https://scriptinghelpers.org/questions/19962 Goulstem 8144 — 8y

1 answer

Log in to vote
1
Answered by 8 years ago
Edited 8 years ago

The code you're using for your function is very, very unnecessary; you don't need to go that far, as it's really, really simple: all you need to do is use the for loop, like the one you're using, but w/o all those calculations & if statements.

All you require, as you used, is the for loop & the sub function:

local SomeStringToUse = 'Stringy-string!!' -- Our string, which will be used for the following for loop; variable "Welcome" represents the string

for x = 1, SomeStringToUse:len() do -- Starting position, and end position; "SomeStringToUse:len()" returns the number of characters there're in "SomeStringToUse," or the length of the string: you can also use "#SomeStringToUse" to accomplish this as well
    print(SomeStringToUse:sub(1, x)) -- Will print the string as the substring increases.
    wait(1 / 44) -- Yields the code for 1-44th of a second
end -- Ends code

And when you fire this, it'll look like this in the Output:

--[[
    S
    St
    Str
    Stri
    Strin   
    String
    Stringy
--]]

And so on; it'll work (more than likely) as you intended your code to be like.

You over-complicated something simple, but that's all right, we're only human. :)

Stuff touched on but didn't go into great detail about

  1. Output

  2. Sub Strings

  3. For loop

  4. If statement

Hope this helped you in any way. :)

Edit Just read the title... Oops. ;-;

Your problem is that Tick may not be existent at the time of execution of the code; a way to counter this is to use the handy-dandy WaitForChild function! * Choir * ~(OoO~)

It'll look similar to this:

Parent:WaitForChild('Child_Name')

What WaitForChild does is yield the code, and listens for when the child is existent w/in the specified parent; the parent is require, b/c that's where it's going to wait for the child in, and so is the argument (the name of the child), b/c it'll use that to wait & find the child/ object.

I hope this helped you in any way. :)

0
I solved it anyways xd TheUniPiggy 77 — 8y
0
Ah, ok. :P TheeDeathCaster 2368 — 8y
0
And thanks for accepting my answer anyways. :) TheeDeathCaster 2368 — 8y
Ad

Answer this question