I'm working on a game with my friend, and both of us can't find a tutorial on how to make a random transparency script
What I mean by that is we want to make 3 parts disappear and reappear randomly with math. randoms but we don't know how, as we are new to Roblox Lua
It is a server side script and nothing happens when I hit play
Here is a snippet:
https://imgur.com/a/jjCwS5L
math.random
will return any number between a,b. Therefore it can return decimal numbers too. you can use math.ceil
to get either expected number. (math.ceil rounds upwards.)
This is very simple. You can place all Bricks into a Table, and randomly selecting the Element. First and foremost you’ll reference the Parts and set them up. Like so:
local Parts = {workspace.Part1,workspace.Part2,workspace.Part3}
This is Table, if you didn’t know already. It allows you to set two or more values in a single variable.
Then, we will use said math.random
to select a random Element in Parts
. As Tables use numerical indexing to reference each Element.
math.randomseed(tick()) -- increase actual randomization local RandomPart = Parts[math.random(1,#Parts)]
As you know, math.random
returns any number between a,b. Square brackets are used to index an Element. For example Parts[2]
would be Part2
. We can use math.random
to give us a random index in Parts
. For us to properly do so, you’ll have to give it 1, as the lowest index, and #Parts
, which will return the total length of Parts
, which will be the highest; last.
After we’ve got our randomly selected Part: RandomPart
, you can run it through whichever transparency function you’ve written.
Hope this is what you’re looking for! If so, don’t forget to accept!