What do you want to achieve? Keep it simple and clear!
I want from someone a clear answer of the next listed scripting things I don’t understand. Included, if possible an example.
What is the issue? Include screenshots / videos if possible!
I have some scripting terms that I don’t understand.
Pcall
Warn
In some scripts they having this kind of local variable:
local firstWord, secondWord = [Variable]
When u are using (“Hello”) and when u are using “Hello”?
And the last thing is this`, when you use 2 dots and not 1?:
local playerUserId = "Player_"..player.UserId
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I am now 1 day long busy with this but i can’t find the correct answer.
Pcall - I don’t know
Warn - Equals Print but used to warn a error(or something like that) on output.
2 Dots - Example print("1 + 1 = " 1+1) - this doen’t work,but if u made print("1 + 1 = " … 1+1) in output will appear: 1 + 1 = 2
…idk how to say… its used to print(or other thing, like variable values) variables and more things in the same print.
The .. is concatination, it is used to associate strings with a variable that can change, for example you have 150 money, and the Money value is in the player.
To show it in a GUI or in a TextFeild with other text you would do: text = "You have ".. game.Players.LocalPlayer.Money.Value.. " Money." and it would appear in the textfield as
You have 150 Money
warn() is print(). but instead prints it in orange/yellow text.
pcall - Used to wrap a block of code to prevent errors from going to the output. Returns if the block of code executed successfully or not as a bool (ex. true if successful and false if not) and an error message if it wasn’t successful
Usage:
local success, errormessage = pcall(function()
print("Working")
end)
if (success) then
--if it was successful and no errors occurred
else
--if it wasn't successful and errors occurred
warn(errormessage) --have to call the errormessage variable to see why the pcall or block of code failed
end
pcall is used to prevent from errors stopping the whole script. (I don’t really know how to explain)
Heres an example of a pcall being used:
local success, result = pcall(function()
return datastore:GetAsync(key)
end)
if success then
print(result) -- prints the data
else
warn(result) -- warns the error
end
When you’re using return in a pcall, it would return the value you returned to the second variable if the pcall was successful. If it wasn’t successful it wouldn’t return the value, instead would make that variable the error message as to why it failed.
Short for protected call, pcall is a way to make sure a web request doesn’t fail
Warn()
This is just like print() but the text appears as yellow instead of white. You might also see error() which prints an error. I have never used warn or error.
Brackets for variables
Some developers make variables that have spaces in them, and you must surround these variables with brackets if they have spaces.
Parentheses around a string
This doesn’t really mean anything, it’s just a way some people like to organize their code.
The two dots
You use the two dots for concatenation, or for combining strings.