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
01 | local gui = script.Parent |
02 | local tick = script.Parent.Tick |
03 | local text = script.Parent.TextLabel |
04 | if game.Players.LocalPlayer.Name ~ = "Player" then |
05 | end |
06 | if text.Visible = = true then |
07 | function mes(text 1 , text 2 , wait 1 ) |
08 | for i = 1 ,string.len(text 2 ) do |
09 | if string.sub(text 2 ,i,i) = = " " then |
10 | text 1. Text = string.sub(text 2 , 1 ,i) |
11 | i = i+ 1 |
12 | wait(wait 1 ) |
13 | else |
14 | text 1. Text = string.sub(text 2 , 1 ,i) |
15 | i = i+ 1 |
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
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:
1 | local SomeStringToUse = 'Stringy-string!!' -- Our string, which will be used for the following for loop; variable "Welcome" represents the string |
2 |
3 | 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 |
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 |
6 | end -- 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
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:
1 | 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. :)