Posts: 1,295
Threads: 137
Joined: Jan 2011
Reputation:
0
Okay. So here is my script, obviously it doesn't work, because of my lack of scripting knowledge, and I was wondering what is missing.
The script is a script to change the player's layer by pressing q and e.
print("Yo, yo, yo. Whazzup mah homiiieeeess!!")
P = Player.Layer
Function Keydown (q)
P = P +1
Function Keydown (e)
P = P -1
Shiggity Shiggity Shwa
Posts: 5,683
Threads: 413
Joined: Aug 2012
Reputation:
0
08-04-2011, 09:00 PM
(This post was last modified: 08-04-2011, 09:01 PM by Whyrrak.)
Well, you need to define Player.
And you need ends on functions.
And you need link(event, function).
And of course you can't have a layer of -1 or of 3.
Here's how I would code this script, inside a tool.
Oh yeah and [ lua ] tags FTW!
[lua]
local tool = script.Parent -- creating a variable
local player = tool.Parent.Parent -- creating a variable from a variable
local character = player.Character
local layer = character:getChild("Body").Layer
local minimum = 0 --you can't have a layer of -1
local maximum = 2 --you can't have a layer of 3
--That's all the variables.
print("Variables loaded!")
function RaiseLayer()
if layer < maximum then
--if the character's layer is below 2 then
layer = layer + 1
else
--if the layer is 2 then
print("You are on the highest layer already.")
end end --Always remember the ends for "do"s, "if"s, and "function"s.
function LowerLayer()
if layer > minimum then
--if the layer is above 0 then
layer = layer - 1
else
--if the layer is 0 then
print("You are on the lowest layer already.")
end end
function KeyPressed(key) --This function contains a variable in itself.
if string.lower(key) == "q" then --Works with caps on
RaiseLayer() --Calls this function
elseif string.lower(key) == "e" then
LowerLayer() --Calls that function
end end
print("Functions loaded!")
link(tool.KeyDown, KeyPressed) --Links the tool being keypressed with the function
[/lua]
Posts: 1,553
Threads: 201
Joined: May 2011
Reputation:
0
[lua]
game.World:remove();
[/lua]
Put that in your game than play it.
Posts: 52
Threads: 5
Joined: Jul 2011
Reputation:
0
Lol better than mine a lot of times.
Posts: 1,586
Threads: 85
Joined: Apr 2011
Reputation:
0
I already made a script to do this :3
But anyway
You need to put some function ends
You need to call the functions
And you need to actually check the keydown to see what key was pressed
And you need to define player