Showing posts with label Scripting Help. Show all posts
Showing posts with label Scripting Help. Show all posts

Friday, June 14, 2013

The Changed Function

Changed is a function used often around ROBLOX, many users consider it a treasure to use in their game as it's brilliant at firing certain options once an element/property of an item with the changed event in it has been changed.
Example:
game.Lighting.Changed:connect(function(change) --This calls the function, names the event, stores the name of the changed property into the variable 'change'. 
if change == "TimeOfDay" then --Makes sure the changed item of lighting is the Time before it does anything.
 for _,parts in pairs (game.Workspace:GetChildren()) do --This gets the parts in the workspace, stores them into a variable named 'parts'. 
if parts:IsA("BasePart") then --This checks if the parts superclass/class is a BasePart/Part. 
for _,v in pairs (parts:GetChildren()) do --This gets the children of parts and stores them into the variable v. 
if v:IsA("Light") then --This checks if the children of parts is a light. 
if game.Lighting.TimeOfDay == "17:00:00" then -- This checks if the time of day is 17:00:00 (in-game time)
v.Enabled = true -- This enables the lights 
elseif game.Lighting.TimeOfDay == "08:00:00" then --This checks if the time is 8am (in-game) 
v.Enabled = false -- This enables if above is true. 
 end end end end end end end) -- This ends the code. 


You can use the changed function to do many things, it is only fired when something in the class you are using it in has changed. Therefore it's easier than using any while loop to keep checking with an if statement.

Fiddle around with the above code, learn from it.

This was a short tutorial/example by Zakary Wilson.
Thanks for reading.

Wednesday, June 5, 2013

Scripting Tutorial: Making A Chat Gui

When coding in ROBLOX Studio for things that will make your games look lots more stylish, you have your cookiez and milk next to you while coding a beautiful addition to your game. On this tutorial, I will create a chat gui, very simple, and can be modified however you wish. If you would like to edit this and do not know what to do, personal message me. (zakary99)

1. Write this in the command bar: Instance.new("ScreenGui", game.StarterGui).Name = "ChatGui" or add a new ScreenGui to StarterGui and name it 'ChatGui'.

2. Add this code to a script in the workspace:
game.Players.PlayerAdded:connect(function(player) -- Main two functions.
player.Chatted:connect(function(msg)
for _,v in pairs (game.Players:GetChildren()) do -- Gets all the players
for _,frame in pairs(v.PlayerGui.ChatGui:GetChildren()) do --Finds the chat children if there is one.
if frame:IsA("Frame") then-- Finds out if the chat's children is a frame
frame.Position = UDim2.new(frame.Position.X.Scale, 0, frame.Position.Y.Scale-0.05, 0) -- moves the frame up.
end
end
frame = Instance.new("Frame", v.PlayerGui.ChatGui)--Makes a new frame for the text.
frame.Size = UDim2.new(0.3, 0, 0.05, 0)--Chooses the main size.
frame.Position = UDim2.new(0, 0, 0.05, 0)--Gives the frame the correct position.
frame.Style = "RobloxRound" -- Makes the frame Roblox Round
frame.ClipDescendants = true -- Makes it so the text cannote escape the frame.
message=Instance.new("TextLabel", frame) -- Makes the message label.
message.Position = UDim2.new(0, 0, 0.5, 0) -- Chooses the correct position inside the frame.
message.TextXAlignment = "Left" -- Makes the text on a left alignment so it has a better length.
message.TextColor3 = BrickColor.new("White").Color --Chooses the color
message.Text = "["..player.Name.."]: "..msg -- Gets the message and player's name inside the message label.
message.FontSize = "Size18" -- gives the message's font size 18
message.Font = "Arial" -- A personal favourite
end
end)

end) -- Ends the functions.

Click here to take the model.


This is just a simple chat gui, you could integrate things like TweenPosition() method and Coroutines.

Thanks for reading,
Any questions? Tweet me @RBX_Zakary99, skype me: Zakary Wilson (hetrozakary), PM me (zakary99)

~Zakary Wilson

Monday, May 6, 2013

ROBLOX Scripting: Using a non-PVP Humanoid

Humanoids can be debated as the most important item that lies within the character of a ROBLOXian, I believe that's true. Without the Humanoid, we do not have the Sitting down property, nor do we have the WalkSpeed, neither run. With a humanoid, you gain the option to have death, but what if you were to, perhaps be Non-PVP, or not allow somebody to kill you with a sword, well. You'd change the name of the humanoid (SUPER SIMPLE), and if you were to convert a sword so that it still works with you even when your humanoid's name is different, that can also be simple.

A simple roblox sword, is a very long script. Each sword is programmed to kill a person with a humanoid named humanoid. You would have to slice through the code to stop a sword from killing somebody with the name "Humanoid" and change it to, well I don't know, "TheNoob". In this case, the sword would only take health from the character with the Humanoid named "TheNoob". In my case, that's what my humanoid is called!!!

But that is way too advanced for now, at the moment I am doing simple scripts.

So, to change the humanoid's name would simply be a script inside the StarterGui, the script would contain...

script.Parent.Parent.Character.Humanoid.Name="Zakary99IsAMassiveNoob"


This would stop players from being able to kill that person, if you are a person who hates that stupid force field, (like me), then you will like this. In my game, Classic Sword Fight, I use an AFK Gui, within the game I have a sword named sword that is inside the lighting, and each player has the same sword. This is the script for the button that turns the player into afk mode..

location;


























I would suggest using this as an afk script, it's very reliable, and hasn't let me down yet..


Thanks,

~Zak





Sunday, May 5, 2013

MarketplaceService: How-to utilize it.

Hello Robloxians!
TechTeam911 here - today, I will be teaching you guys how to use the new feature of Roblox, the MarketplaceService.

What is MarketplaceService?
MarketplaceService is the new service that was unlocked by Roblox recently. It holds a variety of features that scripters can utilize to create in-game purchases (And also retrieve information about an item from the catalog.)



How do I use it?
The methods of MarketplaceService have very few limitations. The only limitation is that if you try to prompt a purchase on a guest, it'll throw you a warning asking you to avoid prompting purchases with guest users (This won't halt your script, it'll just warn you in the output.) Otherwise, there are no other main requirements.



Methods that you need to know:
PromptPurchase
GetProductInfo
PlayerOwnsAsset



PromptPurchase()
Limitations: None.

Arguments: Player,assetId,equipIfPurchased,CurrencyType

What you need to know:

In order to use PromptPurchase, you have to get the service that manages in-game transactions (MarketplaceService). To get the service, you would use this simple line. game:GetService("MarketplaceService")
What the arguments mean:

Player is player, ie: game.Players.Player1.

equipIfPurchased - if the object the player purchased is a gear item, automatically have the character equip it.

CurrencyType, specifies what desired currency (If it's for sale with that currency type) is preferred. Ie: Wanting a user to purchase an item in-game with Robux instead of Tickets. If the item is on sale for only tickets, and you try to specify Robux, it'll prompt the purchase with Tickets, and vice-versa. Two enums (1 = Robux, 2 = Tix). You can also specify which currency you want by using it's name (Ie: "Robux","Tix")

Example script:
game.Players.Players.PlayerAdded:connect(function(player) -- Player entered.
player.Chatted:connect(function(msg) -- Player spoke.
if (string.lower(msg) == "don8pl0x!") then -- See if the non-capital letter version of the message is equal to 'don8pl0x!'
game:GetService("MarketplaceService"):PromptPurchase(player,20573078) -- Prompt the player to purchase the hat 'Shaggy'.
end
end)
end)



GetProductInfo()
Limitations: Excessive requests with this method get throttled. In a nutshell, don't go getting product info for an item every available second, otherwise it'll prevent you from pulling info for a while.

Arguments: assetId

What you need to know:

This is a method that advanced scripters can utilize to pull the product info on an item (Ie: Name, price, date created, etc.) directly from the website.

Warning: Geek language incoming!

When you use GetProductInfo, it returns the information in JSON format on the item you used the method on. By JSON format, I mean that all the data that is returned is in a table for easy access.

Returns: AssetId,ProductId,Name,Description,AssetTypeId,CreatorId,Name,Created,Updated,PriceInRobux,PriceInTickets,Sales,IsNew,IsForSale,IsPublicDomain,IsLimited,IsLimitedUnique,Remaining,MinimumMembershipLevel, and ContentRatingTypeId.

Breaking down what GetProductInfo returns.
AssetId: The AssetId of the product you looked up.
ProductId: Not used by users.
Name: Self-explanatory, returns the name of the item.
Description: Returns the description of the item.
AssetTypeId: Returns an enum that signifies what type of item the asset you looked up is.
CreatorId: Returns the userId of the creator of the asset.
Name: Name of the creator.
Created: Returns YYYY-MM-DD + TT:TT:TT as to when the item was created.
Updated: Returns YYYY-MM-DD + TT:TT:TT as to when the item was last updated.
PriceInRobux: Returns how much the item is priced at in Robux, returns null if it isn't for sale in Robux.
PriceInTickets: Returns how much the item is priced at in Tickets, returns null if it isn't for sale in Tickets.
IsNew: Returns a bool as to whether the item is new or not.
IsForSale: Returns a bool as to whether or not the item is for sale.
IsPublicDomain: Returns a bool as to whether the item is free to take or not.
IsLimited: Returns a bool as to whether the item is limited or not.
IsLimitedUnique: Returns a bool as to whether the item is LimitedU or not.
Remaining: Returns how many (If the item is limited/limitedU) copies of the item are remaining, otherwise returns null.
MinimumMembershipLevel: Returns a number as to what minimum membership level is required to purchase the item.
ContentRatingTypeId: Returns 0 if the item is under 13+, 1 if it is over 13+.

Example script: print(game:GetService("MarketplaceService"):GetProductInfo(20573078)) -- Run in the command bar with the output window open.



PlayerOwnsAsset()

Arguments: Player,assetId

What you need to know:

This is a simple method that tells you if a player owns an item or not.

Player is player, ie: game.Players.Player1

assetId is the assetId of an item you want to see if the player owns or not.

Example script:

game.Players.PlayerAdded:connect(function(player) -- Player entered game.
if game:GetService("MarketplaceService"):PlayerOwnsAsset(player,20573078) -- Does the player own Shaggy?
player:Destroy() --NOOB!!!
print("Noob!!!")
else
print("Ok, he's not a noob.")
end
end)



That's it for the new MarketplaceService - there are more methods and features of the MarketplaceService for more advanced scripters, but these are the basic three methods that you should know.

Thanks for reading! Feel free to PM me on Roblox if you have any questions.
~Tech

ROBLOX Scripting: A Buy Button

I've been on ROBLOX for a fair time now, and I've advanced myself to high scripting knowledge, but when I first started learning to script, this was a hard job. So, I'm going to make it easy for you..

When you're making a shop in a gui, you'll wanna know how much of their leaderstats that player has. And if they have that many then it will take it away, this can be performed with a simple "if" statement. Like so:

My leaderstats name is cash, and my button is in a screengui which is in startergui..

if script.Parent.Parent.Parent.Parent.leaderstats.cash.Value>=20 then
game.Lighting.Item:clone().Parent=script.Parent.Parent.Parent.Parent.Backpack
game.Lighting.Item:clone().Parent=script.Parent.Parent.Parent.Parent.StarterGear
script.Parent.Parent.Parent.Parent.leaderstats.cash.Value=script.Parent.Parent.Parent.Parent.leaderstats.cash.Value - 20
else
print("Can't be bought "..script.Parent.Parent.Parent.Parent.Name.." doesn't have enough.")
end
end
script.Parent.MouseButton1Click:connect(click)

This would take away 20 cash if the player has 20 or more cash, it would also print that the player doesn't have enough cash if they can't buy it.
To see a full understanding of if statements click here.

Thanks for reading this short, and easy post..

~Zakary99

Questions?
Pm me on ROBLOX
or
Tweet me on twitter @RBX_Zakary99

Thursday, May 2, 2013

ROBLOX Scripting: Explaining Values

When being a scripter, having values are essential, I could use a few Values to make a simple inventory system, or to tell whether a plowing field is being used, using a Boolean Value. If you are to be a successful ROBLOX scripter, on your journey you must learn a Value, so I'm gonna teach you.

On the current game I'm making, Forgotten Fate, I have used a various amount of Values with a varied choice of which Value, I used the Boolean Value on a crop field, and a String Value for finding the crop that you want to plant. Somehow with a Value everything can be simpler, most of the Values I uses are implemented on the if statement, for example:

if script.Parent.NoobValue.Value==true then
script.Parent.Parent.Parent.Character.Humanoid.Health=0
wait()
end

That meant if the person is a noob, then they will be killed, that is just one of the simple things you can have done with a value.

You could have an inventory model, which had lots of boolean values, each named after a sword, and if the sword = true then the sword would clone to the players Backpack. Boolean Values and Number Values are probably the most useful in my point of view, Boolean Values are my best friends, well, Lolfunny12345 is my best friend. A boolean value can also take place in a script, like debounce.

local noobboolean = false

That would be how you denounce a boolean value in a script. To have a better understanding of Values, you would have to use them, because I had no idea what ipairs was until I used it. It's all in your brain, it depends on the best way you learn, which makes something easier, I'm writing for people who can learn from articles and reading. But you could probably learn from more ways, perhaps YouTube would have a tutorial somewhere along the line.

Visit Roblox Wiki

Thanks for reading.
Zakary99

Monday, November 26, 2012

Zakky's Scripting Tutorials #1 - Printing

BASICS #1

Printing is a simple thing... You have something called an "output" in ROBLOX Studio, which will display your prints. Printing is often used just to narrow down a diagnostic of a paragraph of code or so. You use prints to organize your scripts too. So if I had a cake generator script....

print("CAKE GENERATORZ LOADED")

That would print a line on the output saying "CAKE GENERATORZ LOADED").
But what if my Cake Generatorz script wasn't working and OUTPUT wasn't helping me fix it? Well... This line could help you diagnose it. Because, if you see the line printed, then there's something wrong with after it. Whereas if it didn't print something would be stopping it.

Examples:
print("zakary99 model loaded")

You can also continuously print my name...

while true do 
print("Zakary99!!")
wait()
end

That would carry on printing my name forever.

This is a very short tutorial.

We will get more advanced as time goes by...

Sunday, November 11, 2012

Mango's Tutorials: Beginning Scripting

Hey guys! I've asked some people and it appears that scripting is something that a lot of users are wanting to understand.

Beginning scripting is very easy to learn, if you have the urge and willpower to overcome the twist and turns that it's rocky road brings fourth. Once you've got the basics down, you'll be able to understand more complicated tutorials.

But before we get started, you'll need to have Roblox Studio set up properly. To do that, open Roblox Studio and start a new project.

Move your mouse over the "View" tab that's located on the top of your screen. your going to want to select "Explorer" and "Properties".

This is what the explorer should look like:


This is what the properties tab should look like:


Once you've got those tabs opened, we can continue on with the tutorial.

Notice when you click something on the explorer, you can change it in the properties tab. And everything that appears in the explorer, is in the game. Also take notice that everything is under "Workspace" in the explorer.

Alright, now I want you to insert a brick, and I want you to name it 'test'. The brick should appear as a "Part" in the explorer tab. Now insert a script. Do this by rolling your mouse over the "Insert" tab on the top of your screen, then click "Insert Object".



A window should come up, select "Script". A "Script" should be added to your explorer.

Double click the script. A window should come up with the text "Hello world" in it. Since we don't really need that there, your going to want to erase that.

What we're going to do, is change some of the properties of our 'test' brick using a script. In order to do that, we first have to tell the script what we want to edit. But, how do we do that? Simple.

First, we tell the script to look under 'game', since everything is in the game, obviously the brick is going to be in there. Then, if you look at the explorer, your going to want to identify it under 'Workspace' as well.

It should look something like this:

game.Workspace.test

First it looks in game, then Workspace and then it's directed to our brick, 'test'.

Now we want to change our brick.

Click the 'test' brick on the explorer and look at the properties tab. Let's change the transparency, to do that, we're going to show the script what we want to change. So add 'transparency' to the script, like so:

game.Workspace.test.Transparency

Now we can go ahead and change it. We want to add an '=' sign and put in the decimal you prefer, just like this:

game.Workspace.test.Transparency = 0.3

Congratulations! You've created your first script. Push the play button, if you've done everything correctly,  the 'test' brick should become transparent.

Send me a message HERE to ask me any questions!
Don't forget to comment!

Friday, September 28, 2012

Tween Position & Size

Before anything, I did post this by my own accord. Because I thought you, the readers would want to hear from me ASAP!

Tweening position:

script.Parent.Frame:TweenPosition(UDim2.new(0.5, 0, 0.5, 0))

This would put the frame in the parent of the script to the position of 5 by 5, also meaning that you would not have to use any long scripts.

Lets take a closer look...

script.Parent.Frame:TweenPosition(UDim2.new(0.5, 0, 0.5, 0))

'script.Parent.Frame' - locating the frame.

:TweenPosition() - the method used to move a gui to a position in a manner smooth and risk-free.

UDim2.new(0.5, 0, 0.5, 0) - defining the position you want the gui to be at by the end of the tweening.

Tweening the position is one of the most easy ways to move a Gui smoothly. Even an idiot could use this method. It helps a lot, you could also choose the manner you wish for it to enter, you could make it bounce with 'script.Parent.Frame:TweenPosition(0.5, 0, 0.5, 0), "Out", "Bounce")'. This would bounce the gui when it reaches it's destination. Although the bounce method doesn't give of a sound unless you have scripted it, it's still a very nice way to have a Gui move itself in.
.
Tweening can also involve size, even sizeandposition, but I think if you know Size and Position, you could easily use "PositionAndSize". Size is the same as position, but instead of saying TweenPosition, the hardest bit is changing TweenPosition to TweenSize.
Both TweenSize and TweenPosition come in handy when making a game, the enums are even better. With Tweening, you can choose how long you with the gui to take before it reaches it's destination, for a smoother tween you could set it as a high number of seconds, whereas if you were using a small time you would reach the destination quicker.

Suggestions

With this method, I personally have a suggestion that they make "TweenPartPosition" and "TweenPartSize" making it easier for us, the users to move bricks to a different position in a better transition than making everything run from a for loop or so.

My Opinion

In my opinion, Gui Tweening is a great addition to ROBLOX, and they should carry on making options like it. Great job!

Review News

Sorry about my delay, I should have one up and running today, I have actually been really busy with programming, I mean, yesterday I learnt a whole programming language in one day. And I was too tired to carry on blogging for that day. So if you are reading this tomorrow then there's probably a review up. :)

~~Zakary99
"Did you know, place reviewing is the best department?"

Saturday, August 11, 2012

Some Gui Functions!

Yo, it's me again. Zak. I am going to show you some gui functions and the way of changing them. This will be a short tutorial on GUI. So remember- pay attention!

Creating your own function:
Creating a function of your own can easily be done, you can just do something like...








So, this is a function I made up in a few seconds.
Explanation:
function hover() --Custom function
BLANK--in these blank lines, will be what the script will do when you "hover" over the gui.
BLANK
BLANK
end --Ending the function.
script.Parent.MouseEnter:connect(hover) --script.Parent=the button you will hover over. MouseEnter:connect(hover)= connects the custom function to the mouse enter method.

Now, we'll add some things inside...











Here I have a frame, textbutton and a screengui - obviously! :P
The frame is not visible, so we can make it visible when you hover over it!
Inside the code:






A short video, what it does:
What about other functions?
Now, MouseEnter() is just one method. There is tons of others, and they never stop....
How about an intro? All we need is a frame, a screengui, and a textlabel!!
How about this...
Frame Size= {1, 0, 1, 0}
Frame position= {0, 0, 0, 0}
TextLabel Size = {0, 0, 0, 0}
TextLabel Position = {0.5, 0, 0.5 0}
[Note]: The TextLabel is in the Frame.
The script that is in the frame:









You can just cut out the textstroketransparency if you aren't using TextStroke. :)
What it does:
If you want to delete the background after the text has faded, or even fade the background at the same time, just do this instead of the code above...

wait(3)
for i=0.01, 1, 0.01 do
script.Parent.TextLabel.TextTransparency=0+i
script.Parent.TextLabel.TextStrokeTransparency=0+i
script.Parent.BackgroundTransparency=0+i
wait()
end

Friday, July 27, 2012

A Small Scripting Tutorial: UDim2.new

So, a lot of people have been asking me to make a scripting tutorial. I never actually agreed. But people were saying RN were low on some scripting tutorials, so I may continue doing this in the future if people find them helpful.

What is UDim2?
UDim2 is like the CFrame of a gui, with UDim2 you can move guis and manipulate them to your willing. Like Quadratum Havoc, when you press 'Q' a gui flies into the screen. This is one of the great things you can create with the object UDim2.

How do we use UDim2?
UDim2 is actually not that hard to use in the slightest, as long as you have a text button, and a script with a function. You can move it anywhere.

A script involving UDim2:
function ZakaryIsEpic(mouse)
script.Parent.Parent.TextButton.Position = UDim2.new(0.5, 0, 0.5, 0)
wait()

script.Parent.Parent.TextButton.Position = UDim2.new(0.6, 0, 0.6, 0)
wait()

script.Parent.Parent.TextButton.Position = UDim2.new(0.7, 0, 0.7, 0)
wait()
end


script.Parent.MouseButton1Click:connect(ZakaryIsEpic)
The Function Line: The function line is just the function. (HAS TO HAVE MOUSE)


UDim2, the UDim2.new line would make the TextButton have the position {0.5, 0, 0.5, 0}.


The wait line makes it wait the lowest it can, (wait(0.03)).
The end line ends the function


And the connect line connects the function.


But what if we don't want to write this much?
Well, problem solved, we have the for function...


function ZakaryIsEpic(mouse)
       for i=0.01, 0.5, 0.01 do
              script.Parent.Parent.TextButton.Position = UDim2.new(0+i, 0, 0+i, 0)
              wait()
       end
end


script.Parent.MouseButton1Click:connect(ZakaryIsEpic)


Instead of writing every line of code to do it, you can just use for. This code would make the textbutton move 0.01 every 0.03 second, and it would move many, many times a second. It would have to move to 0.5, so it would move around 500 times. For can also be used for other things like transparency, but I won't get into detail with that on my first scripting tutorial on ROBLOX News.


I'm Zakary99 and thank for for reading this tutorial.
Want news on my latest projects/posts?
Follow me @RBX_Zakary99

Friday, June 22, 2012

Scripting Help #1

Hello, BCGames here. I'm going to be posting daily scripting help. The problem with most people trying to learn to code Lua is not that they can't, but rather they try to speed through it. I have been coding Lua for three (3) years now. And I'm still learning! Today's topic will be about the different types of loops. The most commonly used loop is the while loop. While there isn't a problem with it, the way most people use it, does result in issues. Here is the typical useage:


while true do
   wait() 
   -- code 
end

Now, that's fine and dandy, only that could create massive lag. Here is a better version:

while true do
   wait(2)
   -- code
end

The first example will run about 2,000 time a minute, while the second will only run 30 times a minute.

The next type of loop is called the for do loop. This loop will make it run a certain amount of times. Here is an example:


for i=1,10 do
   wait()
   print(i)
end


This will print the numbers 1-10, then stop. There are many ways to use the for do but those are more advanced and I'll get to that in a later post.

The final loop is the repeat until loop. This will repeat a piece of code until a criteria is met. Here is a simple example:


x=10
y=0
repeat
y = y +1
wait(5)
until y == x



This will continue the loop until the value of y is the same as the value of x.

I hope this helped!

BCGames out! Remember to follow me on twitter! I'm @Zynnar!

Tuesday, July 26, 2011

New Objects for advanced Scripters!

There are two new objects that will be helpful for advanced scripters!
The objects are:
CustomEvent
CustomEventReceiver


Here is how you would use them:


-- test custom events by connecting an event to a receiver, then raising it
local receiver = Instance.new("CustomEventReceiver")
receiver.Receive = function(num)
print("RECEIVED A NUMBER:", num)
end

local event = Instance.new("CustomEvent")
event:Connect(receiver)
-- receiver.Receive callback will now be called if event.Raise is called

event:Raise(42)


For more information, look at the object browser in ROBLOX Studio.
Help>Object Browser

-BCG

Saturday, July 23, 2011

New ROBLOX Feature! Place Teleportation!

Hey guys! ROBLOX has made a new feature that many have wanted! You can now teleport from one place, to another without having to leave that game! In honor of this great new feature, I would like to explain how to use it!

WARNING! SCRIPTING CONTENT!


game:GetService("TeleportService"):Teleport(1818)


Looks simple yes? It is! Now, if you don't know what a LocalScript is, then read this page: LocalScript

Ok, now you should know what LocalScripts are! So, in order to teleport someone to another game, it must be in a LocalScript.

There are two functions for TeleportService. Here they are:


game:GetService("TeleportService"):Teleport(int placeId)
--Teleports the LocalPlayer to the given placeId

game:GetService("TeleportService"):TeleportToSpawnByName(int placeId, string spawnName)
--Teleports the LocalPlayer to the given placeId and spawns them at the SpawnLocation named spawnName if found


I made a Gui as soon as I knew how to use the functions, which was before the feature was even out, and using it, you can now place actual game ads in your game that will allow people to teleport right to the advertised game!

Here is the Gui: BCGames' Game Ad GUI

To use this, there are a few things to edit.

First thing is the Table. The table looks like this:


Ads = {
{PlaceId,"PlaceName"},
{PlaceId,"PlaceName"}
}


Now, to add a place to the advertised list, you would edit it like so:


Ads = {
{3138584,"Sandbox BC"},
{46315274,"Sandbox NBC"}
}


You can add as many as you want! Just remember to add a comma at the end of each '{PlaceId,"PlaceName"}' EXCEPT for the last one!

There are two other options.
Position and Randomize.
With Position you can choose where the Gui will be placed.
Randomize makes the Ads appear in a random order rather than in a certain order.

Enjoy!

PS: The model is actually a LocalScript, and will create the Gui when a player enters the game. Simply double click the LocalScript to edit it!

-BCGames

Saturday, June 11, 2011

Scripting Help 6/11/11

Dear BCG,
How can I make it so my game will evenly sort my teams when a new game starts?
-NeedingHelp

Dear NeedingHelp,
That's simple! First thing to remember is that you need to have a effective method of doing so. For me, that method is using variable change. Here's an example:


Team = 1
TeamColor1 = "Really red" --Change to Team 1's color
TeamColor2 = "Lime green" --Change to Team 2's color
for _,v in pairs(game.Players:GetPlayers()) do
if Team == 1 then
Team = 2
v.TeamColor = BrickColor.new(TeamColor1)
elseif Team == 2 then
Team = 1
v.TeamColor = BrickColor.new(TeamColor2)
end
end


Friday, June 10, 2011

Scripting Help 6/10/11

Dear BCG,
in the following:

function onTouch(part)

What is the '(part)'?
-dudelonutoipitepidermislolwhyisthereskininthere

Dear dudelonutoipitepidermislolwhyisthereskininthere,
The (part) indicates what to call the touched part as. For example,

function Touch(part)
part:remove()
end
script.Parent.Touched:connect(Touch)

So brick 1 falls on top of brick 2. Brick 2 has that script in it. When brick 1 hits brick 2, brick 1 will be removed. So part allows the script to recognize the object that touched the brick the script is in.

Thursday, June 9, 2011

Daily Scripting Help 6/9/11

Dear BCG,
I was editing a dialog shop when I discovered when you buy it and it goes to backpack it goes away when you die. When it goes to starter pack you don't get it right away. how do you make it so it goes both to starterpack and backpack?

-forgotoldacount

Dear forgotoldacount,
It's very simple! Parent it to both the 'Backpack' and the Player's 'StarterGear'! :D
Here:


local tool = game.Lighting.Sword2
script.Parent.DialogChoiceSelected:connect(function(player,msg)
if msg == "InputSt00fHere" then
tool:clone().Parent = player.Backpack
tool:clone().Parent = player.StarterGear
end
end)


You will need to edit the msg, and the player value in the function of course!

Wednesday, June 8, 2011

Scripting Help 6/8/11

Dear BCG,
What I would like to know is, how do I create a loop in a script? By that I mean like having a brick flash colors or something, over and over and over. I hope you can help me...

P.S. ROBLOX News is
awesome!
-cblack9999

Dear cblack9999,
for loops are very simple. They are used to repeat something a certain amount of times. For example, to make a brick flash colors using a for loop, you can make it flash only a certain amount of times. For example:


for i=1,4 do
script.Parent.BrickColor = BrickColor.new("Really red")
wait(0.2)
script.Parent.BrickColor = BrickColor.new("Really blue")
end

That will run four times. However, there is a way to make it completely random! Just by using BrickColor.random()! Here is an example:

for i=1,4 do
script.Parent.BrickColor = BrickColor.random()
wait(0.2)
end

Here is a breakdown.

for

That basically says 'do the following'....The next part:

i=1

That says 'start at one'.
The final part:

,5 do

This says 'Until i equals 5 continue'.
All in all:

for i=1,5 do
print("Loop has run "..i.." times!")
end


Tuesday, June 7, 2011

Scripting Help 6/7/11

Dear BCG,
In what context would you use 'end)' with the ')' next to it?
-pie1183

Dear pie1183,
You would do so when creating an anonymous function. An anonymous function is a function with no name. Here is an example:


game.Players.PlayerAdded:connect(function(p)
print(p.Name)
end)


Note that the 'end' ends the function, and the ')' closes the open '(' in the first line.