Click here to Skip to main content
15,890,609 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi. I'm making a game on the ROBLOX platform using Lua coding language. I need to make it so that every time the game is loaded, a brick/part is spawned in 1 of 4 locations RANDOMLY. I have a capture the flag game, and there are four castles. I want my flag part to spawn in any of the 4 towers when the game begins, randomly. Does anyone know how to do this?

What I have tried:

I have tried looking up many other tutorials, but they do not accomplish my intents. They always show what to do to make the brick spawn in completely random places, which is not what I need in this case. I want the brick to spawn in 1 of 4 already specified locations, randomly each time. Thanks!
Posted
Updated 28-Jul-20 20:01pm

Please, read the question, and think about what you are trying to do.

You have code to generate a random location: you want code to select one of four locations.
So ... modify the random code to generate a number between 1 and 4 (or better, 0 and 3) inclusive and use that value to select which one of the four towers you want. Then use that location as the place to locate your flag.

Development isn't about "Finding code" that will exactly fit your needs: you will have to alter almost any code you find to do what you want (or better, understand what you are doing and write it yourself) ...
 
Share this answer
 
Lua
local tower = math.random(1,4)
See Lua 5.3 Reference Manual[^].
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900