Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Can anyone help me with a random transparency script?

Asked by 5 years ago

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

0
I changed random to ran and the script still doesn't work. joerboyneon6572 -5 — 5y
0
I personally reccomend learning coding before making a game. Not looking up tutorials on specific things. I've made that mistake. User#24928 0 — 5y
0
HOWEVER that doesn't mean you can't use scripting helpers as help. User#24928 0 — 5y

1 answer

Log in to vote
1
Answered by
Ziffixture 6913 Moderation Voter Community Moderator
5 years ago
Edited 5 years ago

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!

0
Alright this helped thanks joerboyneon6572 -5 — 5y
0
I accepted the answer for you. But please accept answers next time User#24403 69 — 5y
0
Thanks Incap Ziffixture 6913 — 5y
Ad

Answer this question