- BrickPlanet Forum
 - Game & Scripting Discussion
 - Simple Lua script to create an object on button press
 
                                                        Simple Lua script to create an object on button press
                        
                    
                                        Posted Jul 20th 2025 at 9:51PM
                                    
                                    
                                                                    
                                                                            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!
                            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!
                                        Posted Jul 21st 2025 at 5:16PM
                                    
                                    
                                                                    
                                                                            Cool good job on helping the beginners :)
                                                                    
                            
                                        Posted Aug 7th 2025 at 5:42AM
                                    
                                    
                                                                    
                                                                            thats nice
                                                                    
                            
                                        Posted Aug 20th 2025 at 1:52AM
                                    
                                    
                                                                    
                                                                            RegisterEvent("ButtonPressed", function(p)
CreateObject("Ball",{x=0,y=5,z=0}):ApplyForce(Vector3(0,10,0))
end)
this would be alot more compact
                            CreateObject("Ball",{x=0,y=5,z=0}):ApplyForce(Vector3(0,10,0))
end)
this would be alot more compact
                                        Posted Aug 20th 2025 at 8:20PM
                                    
                                    
                                                                    
                                                                            But it wouldnt really help if its that compact, just makes it harder to read. Imo, jhon doe's beginner-friendly version wins xP
                                                                    
                            
                                        Posted Aug 22nd 2025 at 11:15PM
                                    
                                    
                                                                    
                                                    Originally posted by 
                                                    
                                                                                                                    impatience
                                                                                                             
                                                    on Aug 20th 2025 at 8:20PM
                                                
                                                
                                                                                                        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
                                                                    
                            
                                        Posted Aug 22nd 2025 at 11:42PM
                                    
                                    
                                                                    
                                                    Originally posted by 
                                                    
                                                                                                                    impatience
                                                                                                             
                                                    on Aug 20th 2025 at 8:20PM
                                                
                                                
                                                                                                        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
                                                                    
                            Search Forum
Thread Info
Replies
                            6
                        Views
                            19