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

01local gui = script.Parent
02local tick = script.Parent.Tick
03local text = script.Parent.TextLabel
04if game.Players.LocalPlayer.Name ~= "Player" then
05end
06if text.Visible == true then
07function mes(text1, text2, wait1)
08    for i=1,string.len(text2) do
09        if string.sub(text2,i,i)==" " then
10            text1.Text=string.sub(text2,1,i)
11            i=i+1
12            wait(wait1)
13        else
14            text1.Text=string.sub(text2,1,i)
15            i=i+1
View all 25 lines...

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:

1local SomeStringToUse = 'Stringy-string!!' -- Our string, which will be used for the following for loop; variable "Welcome" represents the string
2 
3for 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
4    print(SomeStringToUse:sub(1, x)) -- Will print the string as the substring increases.
5    wait(1 / 44) -- Yields the code for 1-44th of a second
6end -- Ends code

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

1--[[
2    S
3    St
4    Str
5    Stri
6    Strin  
7    String
8    Stringy
9--]]

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:

1Parent: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