|
| 17 Nov 2012 05:09 PM |
--Kill command start if game.Players:findFirstChild(script.Parent.Parent.Box1.Text) ~= nil or script.Parent.Parent.Box1.Text == "Me" or script.Parent.Parent.Box1.Text == "me" or script.Parent.Parent.Box1.Text == "Everyone" or script.Parent.Parent.Box1.Text == "everyone" and script.Parent.Parent.CommandBar.Text == "Kill" or script.Parent.Parent.CommandBar.Text == "kill" and KillLock ~= true then if script.Parent.Parent.Box1.Text == "Everyone" or script.Parent.Parent.Box1.Text == "everyone" then for Count = 1, #game.Players:GetPlayers() do game.Players:GetPlayers()[Count].Character:breakJoints() end elseif script.Parent.Parent.Box1.Text == "Me" or script.Parent.Parent.Box1.Text == "me" then if game.Players[script.Parent.Parent.Parent.Parent.Name].Character.Humanoid.Health == 0 then GuiError.new("You are already dead") game.Players[script.Parent.Parent.Parent.Parent.Name].Character:breakJoints() else game.Players[script.Parent.Parent.Parent.Parent.Name].Character:breakJoints() end elseif game.Players:findFirstChild(script.Parent.Parent.Box1.Text) and game.Players[script.Parent.Parent.Box1.Text].Character.Humanoid.Health == 0 then GuiError.new(""..script.Parent.Parent.Box1.Text.." is already dead") game.Players[script.Parent.Parent.Box1.Text].Character:breakJoints() elseif game.Players:findFirstChild(script.Parent.Parent.Box1.Text) then game.Players[script.Parent.Parent.Box1.Text].Character:breakJoints() end --Kill command end
This is the kill Player the kill everyone and the kill me command.
It has to have a lot of checks to make sure it dosnt get Disconnected event because of exception...And it has a little bit for looks (The "GuiError.new (I have that function at the top of the script))
So is it more complicated then it should be?? |
|
|
| Report Abuse |
|
|
|
| 17 Nov 2012 05:12 PM |
| For your level of scripting, maybe not. |
|
|
| Report Abuse |
|
|
eJorge
|
  |
| Joined: 09 Jun 2011 |
| Total Posts: 5966 |
|
|
| 17 Nov 2012 05:13 PM |
| I recommend using variables to hold those objects. It's much more efficient and easier to read. |
|
|
| Report Abuse |
|
|
lucas668
|
  |
| Joined: 18 Jun 2008 |
| Total Posts: 6183 |
|
|
| 17 Nov 2012 05:16 PM |
| Not complicated, but really messy. |
|
|
| Report Abuse |
|
|
|
| 17 Nov 2012 05:17 PM |
@eJor Explain?
@Luca How can I fix this? |
|
|
| Report Abuse |
|
|
|
| 17 Nov 2012 05:17 PM |
More variables would be good.
-[::ƧѡÎḾḠΰῩ::]-[::Helper of Scripting and Writer of Wikis::]- |
|
|
| Report Abuse |
|
|
eJorge
|
  |
| Joined: 09 Jun 2011 |
| Total Posts: 5966 |
|
|
| 17 Nov 2012 05:29 PM |
I mean, instead of 'script.Parent.Parent.Box1' declare 'box1 = script.Parent.Parent.Box1' at the start of the script so you don't have to write the same over and over.
Also, pcall is sometimes more practical than having so much if statements.
Wait, I'm trying to make the script more efficient. |
|
|
| Report Abuse |
|
|
| |
|
MrNicNac
|
  |
| Joined: 29 Aug 2008 |
| Total Posts: 26567 |
|
|
| 17 Nov 2012 05:39 PM |
| I notice your referencing this "Box1" object a lot. If you haven't yet, you should find the ROBLOX blog post about code optimization. In this case, it would be worthwhile to store Box1 as a short variable instead of using script.Parent.Parent...... so much. |
|
|
| Report Abuse |
|
|
|
| 17 Nov 2012 05:40 PM |
if there is an error, the script won't stop working
pcall( function ( ) pprint ( "How'd this get printed?" ) end ) print ( "Error didn't stop this from being printed, script continued after errors." ) |
|
|
| Report Abuse |
|
|
|
| 17 Nov 2012 05:43 PM |
@Chop Explain how I can put this in my script please? I understand what it does, Not how to use it with my script.
@Guy Above Chop That was the first thing I learned, I just never used it. Im using it right now though (Adding them) |
|
|
| Report Abuse |
|
|
MrNicNac
|
  |
| Joined: 29 Aug 2008 |
| Total Posts: 26567 |
|
|
| 17 Nov 2012 05:44 PM |
True, but pcall doesn't stop syntax errors, which are found in interpretation. pcall should only be used in short bursts of calls, not to protect extended code.
You can efficiently protect code after you manually interpret it for errors like this:
function RunProtectedLua(stringCode) local Function, posError = loadstring(stringCode) -- notice we don't 'call' the function if not posError then coroutine.resume(coroutine.create(Function)) end end
That also doesn't stop because of calling wait() |
|
|
| Report Abuse |
|
|
|
| 17 Nov 2012 05:46 PM |
Uh....I broke it --Variables start NamePlayer = game.Players:findFirstChild(script.Parent.Parent.Box1.Text) ~= nil NameMe = script.Parent.Parent.Box1.Text == "Me" or script.Parent.Parent.Box1.Text == "me" NameEveryone = script.Parent.Parent.Box1.Text == "Everyone" or script.Parent.Parent.Box1.Text == "everyone" CommandIs = script.Parent.Parent.CommandBar.Text --Variables end
if NamePlayer or NameMe or NameEveryone and CommandIs == "Kill" or CommandIs == "kill" and KillLock ~= true then
The command stop working when I added "CommandIs == "Kill" and CommandIs == "kill" |
|
|
| Report Abuse |
|
|
|
| 17 Nov 2012 05:51 PM |
I fixed it
CommandIs = script.Parent.Parent.CommandBar
CommandIs.Text == "Kill"
But how can I make it so I do not need "Text" |
|
|
| Report Abuse |
|
|
MrNicNac
|
  |
| Joined: 29 Aug 2008 |
| Total Posts: 26567 |
|
|
| 17 Nov 2012 05:52 PM |
Don't ever store a property in a variable, because Lua doesn't have a dynamic data API. This means that:
if you set
local PartName = Workspace.Part.Name
and you changed the name to "LolBrick" then PartName would still be the old one and wouldn't update to the new name. |
|
|
| Report Abuse |
|
|
|
| 17 Nov 2012 05:54 PM |
| I thought you couldn't set properties as variables.. |
|
|
| Report Abuse |
|
|
|
| 17 Nov 2012 06:04 PM |
PlayerDead = Humanoid.Health == 0
Players.Player1.PlayerGui.AdminGui.Enter.CommandScript:23: attempt to index global 'Humanoid' (a nil value)
D: |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 17 Nov 2012 06:13 PM |
instead of this,that.that.that.that
make a variable so it aint all that messy var = this.that.that.that
var.that.... |
|
|
| Report Abuse |
|
|
|
| 17 Nov 2012 06:19 PM |
You can't make a variable hold two values...
There you are trying to save the 0 (number) and the Humanoid.Health (property)
Try doing
local whatever = Humanoid.Health
if whatever == 0 then ~~codehere~~ emd |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 17 Nov 2012 06:20 PM |
WRONG, YOU CAN
local whatever = {.., .., .., ..} |
|
|
| Report Abuse |
|
|
|
| 17 Nov 2012 06:28 PM |
@cnt
That's a table.., I meant as just a normal variable.
No need to use caps. From what he scripted, I assumed he doesn't know about tables enough yet to do that. So chill pls. |
|
|
| Report Abuse |
|
|
|
| 17 Nov 2012 06:46 PM |
I know what a table is
I used one to check if the person with the GUI is a admin :D
--Admin check start
AdminList = {"michaelaqz4", "Name1", "Player1"} -- Add more names
IsAdmin = false
for AdminCheck = 1, #AdminList do
if script.Parent.Parent.Parent.Parent.Name == AdminList[AdminCheck] then
IsAdmin = true
end end
if IsAdmin == true then
else
script.Parent.Parent:Destroy()
end
--Admin check end |
|
|
| Report Abuse |
|
|
eJorge
|
  |
| Joined: 09 Jun 2011 |
| Total Posts: 5966 |
|
|
| 18 Nov 2012 06:05 AM |
There's the simplified script:
box1 = script.Parent.Parent.Box1 commandbar = script.Parent.Parent.CommandBar --Kill command start local original = box1.Text local text = original:lower() local command = commandbar.Text:lower() local player = game.Players:findFirstChild(original) local me = game.Players[script.Parent.Parent.Parent.Parent.Name] --Don't you mean 'script.Parent.Parent.Parent.Parent'? if player and (text == "me" or text == "everyone") and command == "kill" and not KillLock then if text == "everyone" then for Count = 1,game.Players.NumPlayers do local killme = game.Players:GetPlayers()[Count].Character if killme then killme:breakJoints() end end elseif text == "me" and me then me.Character:breakJoints() elseif player then player.Character:breakJoints() end end --Kill command end
I hope it works (and works how you want). You can use it if you want, or you can just read it to see what I mean. |
|
|
| Report Abuse |
|
|
|
| 18 Nov 2012 09:12 AM |
@eJorge That breaks if you add a invalid name though :c |
|
|
| Report Abuse |
|
|