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

I created a text script, and i don't think i created it right, or used the right type of script?

Asked by 7 years ago
Edited 7 years ago

I created a text script, but i'm not sure if i did it right/used the right type of script

Regular script and here's the script itself :

game.StarterGui.ScreenGui.TextLabel.Text:("Hello..")
wait(3)
game.StarterGui.ScreenGui.TextLabel.Text:("Don't Act Like you are.")
wait(4)
game.StarterGui.ScreenGui.TextLabel.Text:("There are other worlds out there")
wait(7)
game.StarterGui.ScreenGui.TextLabel.Text:("I know you like to act crazy and stuff, but")
wait(9)
game.StarterGui.ScreenGui.TextLabel.Text:("Look up at the night sky, there are tons of possibilites")
wait(10)
game.StarterGui.ScreenGui.TextLabel.Text:("You only live so long...")
wait(10)
game.StarterGui.ScreenGui.TextLabel.Text:("Thats all i wanted to say..")
end

Not sure if i did it right.

ps i put the script in workspace, and i don't know if i should have it there or in the screengui as a regular or local

0
Changing this inside of startergui wont update the players visual experience. Make this a localscript, put it inside the GUI and change it to script.Parent.TextLabel.Text = "Text" RubenKan 3615 — 7y
1
Since you're new, i suggest to look at http://wiki.roblox.com/index.php?title=Intro_to_Scripting RubenKan 3615 — 7y
0
Thanks everyone :) , I'm new (very new) Deploy_Coffee 7 — 7y
0
yeah there's quite a bit wrong here lol Perci1 4988 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

Not quite, but you're on the right track. :)

Before we begin to start fixing your code, let's review the problems w/ it:

  1. You set the code up to change the text in the StarterGui service; the StarterGui only clones the GUIs & sets the parent property to the player's PlayerGui, it doesn't replicate the GUI to the player's screen - that's the PlayerGui's job - so w/ your current code, when a player joins, they'll get a specific text, instead of seeing all of them. (This is a common mistake w/ beginners btw, so don't feel down b/c of it. :) )

  2. You set up an End, but there's no loop or function anywhere w/in the code you presented; if this is a snippet (not the whole code), could you provide the rest please? :)

  3. The Text property isn't a function; you have to set the property to a text by doing "GUI.Text = [String]"

(4.) - Something I like to do, rather than using a wait like you're using it your code, is to set the amount of time depending on how many characters there're.

Now, let's begin:

First off, let's create a variable so that you don't have to keep re-typing the same line over-and-over again, which will become tedious & repetitive fast:

local TextBoxForPlayer = game.Players.LocalPlayer.ScreenGui.TextLabel -- Right now, w/ the lack of information, I'm going to assume the code is used in a localscript; LocalPlayer represents a localscript's client, w/o the need of using the name.

Second, lets use the WaitForChild function for the ScreenGui & TextLabel; the WaitForChild function yields the code until a child w/ the same name as the argument becomes existent w/in the specific parent, then return it; why I say lets use this, is b/c if the ScreenGui or TextLabel wasn't existent at the time of execution, your script would break! :O

Now, let's apply it:

local TextBoxForPlayer = game.Players.LocalPlayer:WaitForChild('ScreenGui'):WaitForChild('TextLabel') -- Ugh, I hate to use it like this >.<

Third, since it appears you want the text to change every 3-10 seconds, & change the text before that, let's use a Function in this case (I liked to do this, b/c it doesn't take too long to code, and makes it look cleaner ^^):

function changeTextAndWaitTime(textToLabel, timeOption) -- "changeTextAndWaitTime" is the name of the function, and we will be able to call it on later on; it'll make it easier rather than re-typing the same line of code over-and-over; the "textToLabel" argument will represent a string, then set the "Text" property of "TextBoxForPlayer" to the "textToLabel:" this is a required argument; argument "timeOption" is an optional argument in this case, b/c it can either be used or not, but if used, it'll use the number.
    TextBoxForPlayer.Text = textToLabel -- Sets the TextLabel's text to the selected text (textToLabel)
    wait(timeOption or textToLabel:len() / 35 + 2.5) -- Will wait from either "timeOption," when given a number, or will get the length of the string, textToLabel, divide it by 35, then add 2.5 to the number, and it will use that number as the wait time. (Since your first text is 7 characters long, it'll be 7 divided by 35, which will be 0.2, and add 2.5 to the mixture, thus the number will then be 2.7, and that same number will be used as the wait time (in seconds)
end -- Ends chunk; to note on the "wait" function, the number you give it will be done in seconds, and not minutes, hours, or anything like that; to accomplish that, you'll need to get the amount of seconds that makes up the time. (60 seconds = 1 minute, 3600 seconds = 1 hour) To note, the "wait" function yields the function for a specific amount of time

Looks much better than it did before already, huh..? :D No? Ok... ;-;

Fourth, now that we have our function, changeTextAndWaitTime, we can now begin to apply it to your code; the first argument of the function is what the TextLabel will show, while the second is optional, but if used it will use the given number & use it as the wait time; as stated previously, the wait function will yield the code for a specific amount of time (in seconds):

local TextBoxForPlayer = game.Players.LocalPlayer:WaitForChild('ScreenGui'):WaitForChild('TextLabel') -- Represents the "TextLabel" that will be used in the code

function changeTextAndWaitTime(textToLabel, timeOption)
    TextBoxForPlayer.Text = textToLabel
    wait(timeOption or textToLabel:len() / 35 + 2.5)
end -- Explained previously

changeTextAndWaitTime('Hello...') -- Btw, you'll still have to re-typing the function name over-and-over, but it wont be as tedious & repetitive :)
changeTextAndWaitTime('I like cheese with my nachos...') -- Whaaat? I was hungry. ;-;
changeTextAndWaitTime('...Do you, too?') -- Calling the function('s name) will fire it, btw :P
-- Already explained the functionality & usage of the argument, so I feel it would be tedious & repetitive to repeat the same thing here

And, wah-lah! The end result! Play FFVII Victory Theme Here Now, when fired, it'll show the text to the player! :D

Now, I'm going to stop right here, b/c I feel (& hope) that I've set you in the right path & direction. :)

To note, I didn't add your original texts in, b/c that's your job, and not mine here; otherwise, it'd feel like I did all the work, and just gave you the script; if it were me in this case, I wouldn't feel very proud of that fact, the fact that someone gave me a script, but I didn't do anything more w/ it since someone did it for me: I'd feel HORRIBLE if that were the case w/ me. ;-;

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

  1. StarterGui

  2. PlayerGui

  3. End - Ends a chunk or function, signifying when the code starts & ends.

  4. Strings(/ Texts)

  5. Tabbing/ Indenturing Code

  6. Functions

  7. WaitForChild

  8. Wait (Function)

Hope this helped you in any way. :)

0
Honestly, I dislike my own answer, b/c it only feels like I dumped information & jumbled a lot of facts in, + it doesn't feel 100% genuine to me. -_-* Usually, I take pride in the fact that my answers feel genuine, friendly, overall understandable & clean, but this isn't one of those cases. TheeDeathCaster 2368 — 7y
0
I don't mean to sound so negative about my own answer, but I honestly don't feel proud of it; hopefully I'll do & feel better as the day goes on. :) TheeDeathCaster 2368 — 7y
Ad

Answer this question