So if I name blocks like a1,a2,a3,a4,a5,a6 and so on I want it to make a random one disappear so you can walk through it and stuff and then just randomly reappear in the same space at a random time. I want to make it so that it does one of these random movements every 60s but i have no idea how to make it i am useless at scripting so if someone could write a script for me that would be amazing thank you.
Looking at the above script. You don't need to have scripts inside every part you can just run a single script in the same place as your path/blocks.
For instance: Tree Structure of workspace:
Workspace |¬ Camera |¬ Terrain |¬ Baseplate |¬ Obby Obstacle Path 1 |¬ Script -- The single Brain script |¬ PathBits -- The group containing your Parts Players Lighting <etc...>
In that Script you would paste this:
local Group = script.Parent["PathBits "] --// The path to your blocks (Group them together in a model of folder and name the group then set the path to that group here!) local HowmanytoChange = 256 --// How many parts to change local DoClear = true --// Change Parts back to their original State on each run? local ChanceToChange = 50 --// values between 0 and 100 are good anything beyond these might break things local RandomWaitTime = true --// do we have a random wait time or not? local WaitTime = 60 --// what time to wait before each change --//############# --//# Main loop # --//############# while true do local Bits = Group:GetChildren() --// Grab each part in this Group local CBits = {} HMB = HowmanytoChange <= #Bits and HowmanytoChange or #Bits for i=1,HMB do local ChosenBit = Bits[math.random(1,#Bits)] while CBits[ChosenBit] ~= nil do ChosenBit = Bits[math.random(1,#Bits)] if(CBits[ChosenBit] == nil) then break end end CBits[ChosenBit] = ChosenBit end for k,Part in pairs(CBits) do local Chance = math.floor((math.random()*100)+0.5) if(Chance <= ChanceToChange) then if(Part.Transparency ~= 1) then Part.Transparency = 1 Part.CanCollide = false else Part.Transparency = 0 Part.CanCollide = true end end end table.clear(CBits) CBits = {} if(RandomWaitTime == true) then wait(math.random()*WaitTime) else wait(WaitTime) end if(DoClear == true) then -- if you want to clear last change then change this value to true above! for k,Part in pairs(Bits) do Part.Transparency = 0 Part.CanCollide = true end end end
If you hocked everything up correctly then it should start to change when you hit run or play.
To configure the script to your liking the following values you can play with and an explanation of what they do.
local Group = script.Parent["PathBits "] --// The path to your blocks (Group them together in a model of folder and name the group then set the path to that group here!) local HowmanytoChange = 256 --// How many parts to change local DoClear = true --// Change Parts back to their original State on each run? local ChanceToChange = 50 --// values between 0 and 100 are good anything beyond these might break things local RandomWaitTime = true --// do we have a random wait time or not? local WaitTime = 60 --// what time to wait before each change
Group = script.Parent["PathBits "]
This links up the parts to the correct location
HowmanytoChange
This is how many you want to change each cycle for instance if you wanted only 10 to change each time then set this to 10
DoClear
Do we want to clear/reset each part back to normal before each change?
ChanceToChange
How much of a chance do we want to give each part to change its state?
RandomWaitTime
Do we wait a random amount of time before changing?
WaitTime
The max amount of time before changing,(Note: if the above RandomWaitTime == true
then this will be the max wait time for the random wait time!
If you have any Questions or have any trouble let me know and ill help! :)
Here's a long script for ya buddy, put the script in your part, not a local script, a normal script.
-- remove the --'s in the script, please don't delete the --'s after the script in the same line just like this way shown: print(script.Name) --Print's the name of the script --you can delete this thing above. do not delete anything below. local part = script.Parent --[[ local part2 = workspace.PartName local part3 = workspace.PartName local part4 = workspace.PartName --]] while true do wait(math.random(0, 2)) -- 0, 2 part is a random time selector, 0 is minimum, and 2 is maximum. if you don't want it to be random, the change it to be just "wait(time)" part.CanCollide = false -- makes the part uncollidable part.Transparency = 1 -- makes the part invisible -- part2.CanCollide = false -- makes the part uncollidable -- part2.Transparency = 1 -- makes the part invisible -- part3.CanCollide = false -- makes the part uncollidable -- part3.Transparency = 1 -- makes the part invisible -- part4.CanCollide = false -- makes the part uncollidable -- part4.Transparency = 1 -- makes the part invisible wait(math.random(0, 2)) -- the same thing as the last one. part.CanCollide = true -- makes the part collidable part.Transparency = 0 -- makes the part visible -- part2.CanCollide = true -- makes the part collidable -- part2.Transparency = 0 -- makes the part visible -- part3.CanCollide = true -- makes the part collidable -- part3.Transparency = 0 -- makes the part visible -- part4.CanCollide = true -- makes the part collidable -- part4.Transparency = 0 -- makes the part visible end
You could just make a while true loop that includes a function that waits a given amount of time before disappearing and waits again before reappearing. The code below is to be inserted inside a script in one of the parts.
local part = script.Parent -- Locates the part local function disappear() part.Transparency = 1 --Makes the block disappear. part.CanCollide = false --Optional. Makes the player be able to go through the block end local function appear() part.Transparency = 0 --Makes the block appear. part.CanCollide = true--Optional. Makes the player not go through the block end while true do --while loop appear() wait(60) disappear() wait(60) -- wait 60 seconds end
It is a very easy script! Hope it helped!