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.
how do I make a script that randomly makes blocks disappear and reappear?
3 answers
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! :)
6 comments
I would not recommend intentionally putting scripts inside of the workspace. Keep them in the ServerScriptService, it's there for a reason.
ok thank you so much
If you could @TGazza please help on could you also help on https://scriptinghelpers.org/questions/121620/like-a-report-system-but-for-if-you-have-finished-a-maze please?
Not sure if its possible to do a roblox report like system as it would require a service from roblox. So unless they've added a new sevice this wouldn't be possible, But you could add a message saying "Message me for stuff on roblox" on that popup system
as for the rank change button on a gui, you can only get player ranks but i dont think set, you'll have to do that through the roblox group ranking system.
whops sorry its a bit clearer here @ TGazza https://scriptinghelpers.org/questions/121661/how-do-i-send-messages-to-and-from-roblox
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!
6 comments
how would I make it so that it randomly picks from selected blocks to execute this function?
Place the blocks in a table and randomly pick one
Btw Lightning I see no wrong in your script, but it's a little confusing that the functions have the opposite name of what they do
Oh. Whoops! Eill change that
@UNIMAKZIN00 you would have to put this function in each block with different wait times
This would not work. The whole point of scripting is to make things easier, it defeats the purpose if your intention is to have them place this in every block then go in and edit the script to get it to work.
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
I think use a remote event. like this: game.Players.PlayerAdded:Connect(function() game.ReplicatedStorage.RemoteEvent:FireServer() then for the server: game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function() workspace.Part.Transparency = 1 wait(1) woorkspace.part.Transparency = 0 then put that in a while true do loop