- BrickPlanet Forum
- Game & Scripting Discussion
- Simple Lua script to create an object on button press
Hi everyone! Here’s a simple Lua script that creates an object when a player presses a button:
lua
function onButtonPressed(player) local ball = CreateObject("Ball", {x=0, y=5, z=0}) ball:ApplyForce(Vector3(0, 10, 0)) end
RegisterEvent("ButtonPressed", onButtonPressed) Feel free to ask if you want me to explain how it works or if you need help modifying this script!
Cool good job on helping the beginners :)
thats nice
RegisterEvent("ButtonPressed", function(p) CreateObject("Ball",{x=0,y=5,z=0}):ApplyForce(Vector3(0,10,0)) end)
this would be alot more compact
But it wouldnt really help if its that compact, just makes it harder to read. Imo, jhon doe's beginner-friendly version wins xP
But it wouldnt really help if its that compact, just makes it harder to read. Imo, jhon doe's beginner-friendly version wins xP
good point
But it wouldnt really help if its that compact, just makes it harder to read. Imo, jhon doe's beginner-friendly version wins xP
but it doesnt take up an entire script