1
Roblox Tutorial - How to Improve your scripts (skills) on 5/25/2010, 9:04 pm
The names says it all =]
To start this tutorial you needs a basic "advanced" sintax knowleadg of robloxs lua.
This tutorial is to people that plays script builder or make free models to others people.
The function type verify the type of his parameter
These types can be "number","string","nil","userdata","table"
its usefull to detect if somenoobs sends a wrong parameter to your scripts.
Example of use
function lol(p)
if type(p) == "number" then
return p+1
end
end
you can send everything, dont return a error.
but looks without a function type:
function lol(par)
return par+1
end
b = lol(CFrame.new(1,1,1))
print(b)
(obs: CFrame is userdata)
This results an error cause CFrame is not a number, you cant put Cframe(1,1,1)+1 cause its impossible o.O differents types!
Thats quite easy, i hope, lets continue
Lots people NEVER use classname, but its needed
if you add some "Part" in game.Players at script builder, what you think that happenz?
every command script BUGS a LOT!
thats why the people thinks: "Added in players Player is!"
FIRST: when you put a script a free models, ITS FREE, everyone use, and you dont know nothing about others games!
person299 commands admin makes bugs! he is script master (or was), but at his time no ones uses that ;/
you all needs understand that conditions are made for over-use, there arent drugs!
Exemple of use
Peoples KNOW about className but dont about nil parameters!
a nil parameter dont exists, its like Player(), no parameters ;/
you can use the function type, thats tell you if its nil or not!
but if its a userdata, you need to know if its nil and if its a classname.
the people forget that!
to somthing with double condition, like that:
I mean that OTHERS PEOPLE bugs your script.
Thinks a leaderboard add script
THE SCRIPTS WAITS 5 SECONDS TO ADD THE LEADERBOARD!
and if in 2.5 seconds the player leave the game?
the parameter IS NIL!
you will put leaderboard in a nil place!
well nothing happenz cause its a event and the event will happens every time... (ChildAdded)
but if someone takes your script and add something after the leaderboard code?
anyway, less errors better run
game.Players.Name = "Lol";
only 50% of scripts will work. (or less)
game.Workspace.Name = "Lol"
only 0% of scripts will work (OR LESS!)
Why the error happens:
Bad scripters thinks that game.Players and game.Workspace never changes.
Good scripters change the game.Players.Name to make noobs dont use ban/kick script, is sad, but prevents noob-kick's
How to detect game places without wanting the name
Thats will found workspace,players,lighting and teams, whatever the name of this name.
and store at variables Wo,Pl,Li and Te (Workspace,Players,Lighting,Team)
Make a fake Players:
Gonna makes lots errors =]
DIRECT ERRORS at command scripts =]
Remove the Backpack of everyone on the script builder
No tools and no command scripts
Rename Players
no command scripts
Rename Workspace
no workspace scripts
The games is arround that =]
Remmember:
dont put:
Player.Backpack
put:
local bp = Player:findFirstChild("Backpack")
if type(bp) == "userdata" and bp.className == "Backpack" then
...
Break scripts are the soluctions when youre trapped!
When you found a auto-killer, change the game.Players or game.Workspace name! this will stop!
When you found a auto-slaver name, change the game.Players or game.Workspace name! this will stop!
Rename it back and the script dont come back (only if the scripter writer is good ._.)
The noobs that destroy your games ever are noob, you can pwn they cause that ;p
If youre banned, come with other acount and change game.Players name!
come with other account and HAVE FUN with the people that banned you (and don understand nothing any+)
just rename it back to un-break the server! =]
or ban him in his face =p
This function finds somthing inside the object by a name ;/
is not perfect, but its for things that only works if have a specify name
example:
leaderboard ~ inside a player this CANT have other name
Backpack ~ inside a player this cant have other name
Anyway, findfirstchild works to detects if somthing exists or its just your imagination .-.
ex:
if game:findFirstChild("Workspace") ~= nil then
print("game.Workspace Exists!");
end
understand?
but that most used for others things .-.
ex:
(newplayer = game.Players.Player);
local a = newPlayer:findFirstChild("Backpack")
if type(a) == "userdata" and a.className == "Backpack" then
print("There is a backpack and itsnt a fake.");
Questions
If you wanna be smart, do these question and see if you was right.
1) Improve these scripts:
a)
Description: Delete's a human part without direct killing it
b)
Description: Direct kill a player w/ breakjoints
c)
Description: Gives 10 cash for the user, disactive the giver and change the part giver to Bright Blue (to show its disactived)
2) Re-write the script and make it dont result in a error with the calls.
(it means: you modify the function and dont modify the calls, the script CANT result in a error but need work);
a)
Supose to: Kill the characte
Calls
b)
Suppose to: Remove right and left legs of the player.
Calls
c)
Suppose to send teh msg without raising a error... nevah!
Calls
3) PROVE YOUR MASTERY to yourself :
Only edit the part with the color green
I will put results ... after Xd
i dont like models lots of errors and i think that is somthing for noobs ._.
Credits are mine ;/
To start this tutorial you needs a basic "advanced" sintax knowleadg of robloxs lua.
This tutorial is to people that plays script builder or make free models to others people.
Function Type(value)
The function type verify the type of his parameter
These types can be "number","string","nil","userdata","table"
its usefull to detect if somenoobs sends a wrong parameter to your scripts.
Example of use
function lol(p)
if type(p) == "number" then
return p+1
end
end
you can send everything, dont return a error.
but looks without a function type:
function lol(par)
return par+1
end
b = lol(CFrame.new(1,1,1))
print(b)
(obs: CFrame is userdata)
This results an error cause CFrame is not a number, you cant put Cframe(1,1,1)+1 cause its impossible o.O differents types!
Thats quite easy, i hope, lets continue
className uses
Lots people NEVER use classname, but its needed
if you add some "Part" in game.Players at script builder, what you think that happenz?
every command script BUGS a LOT!
thats why the people thinks: "Added in players Player is!"
FIRST: when you put a script a free models, ITS FREE, everyone use, and you dont know nothing about others games!
person299 commands admin makes bugs! he is script master (or was), but at his time no ones uses that ;/
you all needs understand that conditions are made for over-use, there arent drugs!
Exemple of use
- Code:
function NewP(newPlayer)
if newPlayer.className == "Player" then
...
end
end
- Code:
function onClick(part)
if part.Parent.className == "Model" then
part.Parent:Remove()
end
end
- Code:
function RemoveTool(player)
if player.className == "Player" then
b = player:findFirstChild("Backpack")
if b.className == "Backpack" then
c = b:findFirstChild("Tool")
if c.className == "HopperBin" then
c:remove()
end
end
end
end
Double Conditions
Peoples KNOW about className but dont about nil parameters!
a nil parameter dont exists, its like Player(), no parameters ;/
you can use the function type, thats tell you if its nil or not!
but if its a userdata, you need to know if its nil and if its a classname.
the people forget that!
- Code:
function PKill(player)
if type(player) == "userdata" then
player.Character:Breakjoints()
end
end
to somthing with double condition, like that:
- Code:
function PKill(player)
if type(player) == "userdata" and player.className == "Player" then
player.Character:Breakjoints()
end
end
I mean that OTHERS PEOPLE bugs your script.
Thinks a leaderboard add script
THE SCRIPTS WAITS 5 SECONDS TO ADD THE LEADERBOARD!
and if in 2.5 seconds the player leave the game?
the parameter IS NIL!
you will put leaderboard in a nil place!
well nothing happenz cause its a event and the event will happens every time... (ChildAdded)
but if someone takes your script and add something after the leaderboard code?
anyway, less errors better run
Existing madness
game.Players.Name = "Lol";
only 50% of scripts will work. (or less)
game.Workspace.Name = "Lol"
only 0% of scripts will work (OR LESS!)
Why the error happens:
Bad scripters thinks that game.Players and game.Workspace never changes.
Good scripters change the game.Players.Name to make noobs dont use ban/kick script, is sad, but prevents noob-kick's
How to detect game places without wanting the name
- Code:
function GetGameMain()
local arr_find = game:GetChildren();
local lp1 = 0;
local str_txt = "";
for lp1 = 1, #arr_find do
if (type(arr_find[lp1]) == "userdata") then
str_txt = arr_find[lp1].className;
if (str_txt == "Workspace") then
Wo = arr_find[lp1];
elseif (str_txt == "Players") then
Pl = arr_find[lp1];
elseif (str_txt == "Lighting") then
Li = arr_find[lp1];
elseif (str_txt == "Teams") then
Te = arr_find[lp1];
end;
end;
end;
end;
GetGameMain()
Thats will found workspace,players,lighting and teams, whatever the name of this name.
and store at variables Wo,Pl,Li and Te (Workspace,Players,Lighting,Team)
Make a fake Players:
- Code:
Pl = game.Players
Pl.Name = "LAWL"
a = Instance.new("Model")
a.Parent = game
a.Name = "Players" -- fake players
Gonna makes lots errors =]
DIRECT ERRORS at command scripts =]
Remove the Backpack of everyone on the script builder
No tools and no command scripts
Rename Players
no command scripts
Rename Workspace
no workspace scripts
The games is arround that =]
Remmember:
dont put:
Player.Backpack
put:
local bp = Player:findFirstChild("Backpack")
if type(bp) == "userdata" and bp.className == "Backpack" then
...
Break scripts are the soluctions when youre trapped!
When you found a auto-killer, change the game.Players or game.Workspace name! this will stop!
When you found a auto-slaver name, change the game.Players or game.Workspace name! this will stop!
Rename it back and the script dont come back (only if the scripter writer is good ._.)
The noobs that destroy your games ever are noob, you can pwn they cause that ;p
If youre banned, come with other acount and change game.Players name!
come with other account and HAVE FUN with the people that banned you (and don understand nothing any+)
just rename it back to un-break the server! =]
or ban him in his face =p
FindFirstChild
This function finds somthing inside the object by a name ;/
is not perfect, but its for things that only works if have a specify name
example:
leaderboard ~ inside a player this CANT have other name
Backpack ~ inside a player this cant have other name
Anyway, findfirstchild works to detects if somthing exists or its just your imagination .-.
ex:
if game:findFirstChild("Workspace") ~= nil then
print("game.Workspace Exists!");
end
understand?
but that most used for others things .-.
ex:
(newplayer = game.Players.Player);
local a = newPlayer:findFirstChild("Backpack")
if type(a) == "userdata" and a.className == "Backpack" then
print("There is a backpack and itsnt a fake.");
Questions
If you wanna be smart, do these question and see if you was right.
1) Improve these scripts:
a)
- Code:
function onHit(p)
p:Remove()
end
script.Parent.Touched:connect(onHit)
Description: Delete's a human part without direct killing it
b)
- Code:
function onHit(p)
p.Parent:BreakJoints()
end
script.Parent.Touched:connect(onHit)
Description: Direct kill a player w/ breakjoints
c)
- Code:
function onHit(p)
a = game.Players:FindFirstChild(p.Parent.Name)
a.leaderboard.Cash = 10
a.BrickColor = BrickColor.new("Bright Blue")
script:Remove()
end
script.Parent.Touched:connect(onHit)
Description: Gives 10 cash for the user, disactive the giver and change the part giver to Bright Blue (to show its disactived)
2) Re-write the script and make it dont result in a error with the calls.
(it means: you modify the function and dont modify the calls, the script CANT result in a error but need work);
a)
- Code:
function KillChar(player)
player.Character:BreakJoints()
end
Supose to: Kill the characte
Calls
- Code:
KillChar(game.Workspace.Part);
KillChar(game.Workspace.Parent.Parent)
KillChar([[I like cookies]])
KillChar(13)
KillChar(game.Players.Player) -- This supposes to EXISTS
b)
- Code:
function NoArm(player)
player.Character.LeftArm:Remove()
player.Character.RightArm:Remove()
end
Suppose to: Remove right and left legs of the player.
Calls
- Code:
NoArm(game.Players.Player) -- This supposes to EXISTS
NoArm(game.Players)
NoArm(game.Workspace.Part)
NoArm(1)
NoArm()
c)
- Code:
function OnPlayerEntered(newPlayer)
a = Instance.new("Hint")
a.Name = "Heayaeay";
a.Text = "YOUR NAME IS " .. newPlayer.Name -- yeah... dont forget your name in the middle of the game xp
a.Parent = newPlayer
end
Suppose to send teh msg without raising a error... nevah!
Calls
- Code:
game.Players.ChildAdded:connect(OnPlayerEntered)
OnPlayerEntered("Lawl")
local b = Instance.new("Part")
b.Parent = game.Players
3) PROVE YOUR MASTERY
Only edit the part with the color green
game.Players.Name = math.random(0,1000).. "Háh" .. math.random(100,200)
-- Put your code here --
function onPlayerAdded(new)
new.CharacterAdded:connect(function() new.Character.Name = "My slave" end);
end
game.Players.ChildAdded:connect(onPlayerAdded())
a = Instance.new("Part")
a.Name = "lol"
a.Parent = game.Players
I will put results ... after Xd
i dont like models lots of errors and i think that is somthing for noobs ._.
Credits are mine ;/
Last edited by Gravyerd on 5/25/2010, 9:13 pm; edited 2 times in total














