How do i Make a Random Part on RandomDot it Disappear and Appear

Also i still learning Scripts so i maybe mistake alot

Script:

local RandomDot = workspace.Part
local randomNumber = math.random(2,5)
math.random(2,5)
RandomDot.Transparency = 1
math.random(2,5)
RandomDot.Transparency = 0

Thank you Ya’ll

7 Likes

If you’re trying to make a part disappear and reappear at random:

local randomDot = workspace.Part
local randomTime = math.random(2,5)
task.wait(randomTime)
randomDot.Transparency = 1
--randomTime = math.random(2,5)  <<< Uncomment this if you want to pick another random time
task.wait(randomTime)
randomDot.Transparency = 0
8 Likes

Do you mean like… making a random part in a group disappear? If so:

local RandomDot = “Your group here”
local GroupChilds = RandomDot:GetChildren()
local part = nil
part = GroupChilds[math.random(1,#GroupChilds)]
if part:IsA(“Part”) then
part.Transparency = 1
task.wait(1)
part.Transparency = 0
end

Just make sure that your Group isn’t blank, also sorry for not making it like in coding style bc I forgot how to

4 Likes

at line 1 do i need
local RandomDot = game.Workspace.RandomDot
if no need i will have red underline

with:
image

Without:
image

6 Likes

The “Your group here” was a example, you should replace it with your group, so if it is named RandomDot, it should be:

local RandomDot = workspace.RandomDot

Oh wait, and I almost forgot. Make sure to set the CanCollide to false if you want your part to be not collidable when invisible:

local RandomDot = “Your group here”
local GroupChilds = RandomDot:GetChildren()
local part = nil
part = GroupChilds[math.random(1,#GroupChilds)]
if part:IsA(“Part”) then
part.Transparency = 1
part.CanCollide = false
task.wait(1)
part.CanCollide = true
part.Transparency = 0
end

6 Likes

Oh yeah

local RandomDot = workspace.RandomDot
local GroupChilds = RandomDot:GetChildren()
local part = nil
part = GroupChilds[math.random(1,#GroupChilds)]
if part:IsA("Part") then
	part.Transparency = 1
	part.CanCollide = false
	task.wait(1)
	part.CanCollide = true
	part.Transparency = 0
end

I was try screah “if part:IsA(“Part”) then” on Google cause it have redline and i little fix it

6 Likes

Can I see the code? Just to make sure you didn’t did anything wrong? Make sure the local in the first line should be:

local RandomDot = script.parent.Model.RandomDot

8 Likes

Local scripts (the ones with a blue color) do not run in the Workspace. Please try a Script (white-colored) instead.

7 Likes

:sob: i mistake edit my reply

5 Likes

Oh and ye, TolMLiker851 is right, but I guess you want it to be different for each player? if so, make sure the script is in the StarterPlayerScripts, and like this:

local RandomDot = workspace.Model.RandomDot (or your group)
local GroupChilds = RandomDot:GetChildren()
local part = nil
part = GroupChilds[math.random(1,#GroupChilds)]
if part:IsA(“Part”) then
part.Transparency = 1
part.CanCollide = false
task.wait(1)
part.CanCollide = true
part.Transparency = 0
end

5 Likes

it got error on line 1
RandomDot is not a valid member of Model "Workspace.Model.Model.RandomDot"

3 Likes

Can I see the list on the side? The one which shows you models, parts, folders, Services like workspace and etc? (I don’t know the name of it) Specifically the Group?

4 Likes

This is full model:


and this what i want to scriprt:

5 Likes

The Model of the Model of which the RandomDot is in doesn’t have a specific name, and the parent of that Model has more models called “Model”, that is why it doesn’t work, roblox instead just chooses the first one, you have to make a specific name for that Model to work

For an example, lets say you want to change the color of a part inside another part (gonna call it ppart, lpart for the part inside the another part), which is in the workspace with other parts with the same name, “Part”, since their name are all the same, roblox only chooses the first one because he doesn’t know what part is the ppart because they have all the same name, so if you want to do something with ppart you have to change the name to a different one for it to be unique, or else it will send a error saying that lpart isn’t a valid member of part

4 Likes

also i change “Model” into “ThePower”
image
and then i cnahe the first line is:
local RandomDot = script.parent.ThePower.RandomDot
Right?

4 Likes

Yep, another example which is way easier to understand: Lets say John punched John, but which John punched which John? You don’t know, just like roblox who doesn’t know which model is which model, because they all have the same name, so roblox just chooses the first one.

Also, you put “script.parent”, so I gonna assume it is a script, not a local script, just to remind you because like TolMLiker851 said, local scripts doesn’t run in the workspace

4 Likes

it still error
ThePower is not a valid member of Model "Workspace.ThePower.RandomDot"
i think i need script
local ThePower = somthing?

Yea i was Change into Script idk why i want Localscript before

3 Likes

Make sure the script is parented to the ThePower, not RandomDot.

Also, the model looks really good, keep on the great work!

3 Likes

Thank you i just want make Look like this on game Buckshot
image
also
the Script is:

local ThePower = script.parent.RandomDot
local GroupChilds = ThePower:GetChildren()
local part = nil
part = GroupChilds[math.random(1,#GroupChilds)]
if part:IsA("Part") then
	part.Transparency = 1
	part.CanCollide = false
	task.wait(1)
	part.CanCollide = true
	part.Transparency = 0
end

right?, i think i do something wrong

3 Likes

Lemme check… And yea, should be all good, but you may want to switch it to:

local ThePower = script.parent.RandomDot
local GroupChilds = ThePower:GetChildren()
local part = nil

while task.wait(0.5) do
	part = GroupChilds[math.random(1,#GroupChilds)]
	if part:IsA("Part") then
		coroutine.resume(coroutine.create(function()
			part.Transparency = 1
			part.CanCollide = false
			task.wait(1)
			part.CanCollide = true
			part.Transparency = 0
		end))
	end
end

Since that way it would repeat endlessly and repeatedly, just like in the game.
“corountine.resume(corountine.create(funtion()” is for so it won’t overlap and have to wait 1.5 seconds, since roblox waits to then end

4 Likes