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]
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]