Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Can anyone help me with a random transparency script?

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

3 comments

0

I changed random to ran and the script still doesn't work.

0

I personally reccomend learning coding before making a game. Not looking up tutorials on specific things. I've made that mistake.

0

HOWEVER that doesn't mean you can't use scripting helpers as help.

1 answer

✓ Accepted answer

#Solution to your Issue


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.)


#Randomly selecting a Part


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!

3 comments

0

Alright this helped thanks

0

I accepted the answer for you. But please accept answers next time

0

Thanks Incap

This discussion is preserved as it was. New answers, comments, and votes are closed.