|
So in my game, there's an area called the maze. There are walls all over the place, and a script decides randomly with math.random tick if they are there or not. The current script for the variable "visible" is;
visible = math.random(2)
If it's equal to one, then it's visible. If it's equal to 2, it's invisible. I duplicated the wall with the script to make every single wall random. However, it causes all walls to either be there or not there (All walls visible or all walls not visible). Is there any way to make the variable "visible" local to it's own script? |
|
|
Can you post the whole script?
And why not just do
script.Parent.Transparency = math.random(0, 1)
I tried using visible = math.random(2)
its working prefectly |
|
|
It's also if you can collide with it. Here's the whole script: while true do math.randomseed(tick()) for _ = 1, 2 do visible = math.random(2) if visible == # #### ########################## = 0 script.Parent.CanCollide = true elseif visible == # #### ########################## = 1 script.Parent.CanCollide = false end wait(1200) end end |
|
|
It won't let me post the whole thing, it keeps censoring and glitching. Well, it's also supposed to be if the player can collide with it or not |
|
|
What I'm looking for is how to make variables local to their own script. |
|
|
Put all your maze part in one model, and put this script inside the model
math.randomseed(tick())
while true do
for i, v in pairs(script.Parent:GetChildren()) do
if v:IsA("BasePart") then
random = math.random(0,1)
v.CanCollide = (random < 0.5)
v.Transparency = random
end
end
wait(1)
end
--Change the value inside wait() to change how fast they changed
--Also be sure to delete your old script |
|
|
I can't really understand your script and i don't know much about randomseed
but i guess its either your put wait(1200) in the wrong place that it only changed 1 brick and waited 1200 seconds
or maybe its because you put randomseed inside the loop, that it asked for different seed everytime. |
|
|
The variables are local to their own script, it's math.random() that isn't working properly. It is giving you a random number, but it is giving the same random number everywhere.
Try adding:
math.randomseede(tick())
to the first line of th script. |
|
|
|
Sorry Cowsoncows, unfortunately it's still not working. |
|
|
Each wall has it's own script. |
|
|
Actually, maybe math.randomseed(tick()) is the problem. tick() gives unix time (time elapsed since january 1st 1970) so if every script calls it at the same time, every script is getting the same seed thus has the same output for math.random. |
|
|
@MonoBlockZ
That actually worked! Would you mind teaching me how it works? |
|
|
Thanks for the advice from both of you! Now the maze can't be memorized by players! I really appreciate it! |
|
braylee8Join Date: 2015-06-09 Post Count: 1 |
Hey, my name is Braylee was wondering, since you work for assassin(Like I saw) I want to have earth elemental. Now I know you will decline at ##### BUT! I got scammed my earth elemental was scammed. I don't know by who but all I know is.. that I miss it. And I need you're help, maybe you could just give me a hand and just Do a little of skills at hacking maybe.. And get my knife back? Please, that would mean the world to me! |
|