Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I change one part inside of models, if the models are inside of a folder?

Sorry if that title was a little confusing.

Basically, I have televisions all over the place and they all have screens with a script that changes their image. These televisions are each their own model, but all of the television models are located inside of a folder in workspace called "tvs". The models are called "Hampton TV", and the screen part with the script is called "HamptonScreen".

I want to eliminate all of the individual model scripts, and just have on script controlling all of the screens, if possible.

Please try to help me out if you can. If you need more information, let me know :)

Thanks

I hope these screenshots can help: 1] [(http://prntscr.com/kuhryh)] 2] [(http://prntscr.com/kuhs9n)

The script located inside of "Controller": It works excellent, I really just would like to eliminate the many scripts.

while true do
		script.Parent.Image = script.Parent.Image1.Value
	script.Parent.ImageTransparency = 0.9
	wait (0.01)
	script.Parent.ImageTransparency = 0.8
	wait (0.01)
	script.Parent.ImageTransparency = 0.7
	wait (0.01)
	script.Parent.ImageTransparency = 0.6
	wait (0.01)
	script.Parent.ImageTransparency = 0.5
	wait (0.01)
	script.Parent.ImageTransparency = 0.4
	wait (0.01)
	script.Parent.ImageTransparency = 0.3
	wait (0.01)
	script.Parent.ImageTransparency = 0.2
	wait (0.01)
	script.Parent.ImageTransparency = 0.1
	wait (0.01)
	script.Parent.ImageTransparency = 0
	wait (15)
	script.Parent.ImageTransparency = 0
	wait (0.01)
	script.Parent.ImageTransparency = 0.1
	wait (0.01)
	script.Parent.ImageTransparency = 0.2
	wait (0.01)
	script.Parent.ImageTransparency = 0.3
	wait (0.01)
	script.Parent.ImageTransparency = 0.4
	wait (0.01)
	script.Parent.ImageTransparency = 0.5
	wait (0.01)
	script.Parent.ImageTransparency = 0.6
	wait (0.01)
	script.Parent.ImageTransparency = 0.7
	wait (0.01)
	script.Parent.ImageTransparency = 0.8
	wait (0.01)
	script.Parent.ImageTransparency = 0.9
	wait (0.01)
	script.Parent.ImageTransparency = 1
	wait (0.01)
	script.Parent.Image = script.Parent.Image2.Value
	wait (0.01)
	script.Parent.ImageTransparency = 0.9
	wait (0.01)
	script.Parent.ImageTransparency = 0.8
	wait (0.01)
	script.Parent.ImageTransparency = 0.7
	wait (0.01)
	script.Parent.ImageTransparency = 0.6
	wait (0.01)
	script.Parent.ImageTransparency = 0.5
	wait (0.01)
	script.Parent.ImageTransparency = 0.4
	wait (0.01)
	script.Parent.ImageTransparency = 0.3
	wait (0.01)
	script.Parent.ImageTransparency = 0.2
	wait (0.01)
	script.Parent.ImageTransparency = 0.1
	wait (0.01)
	script.Parent.ImageTransparency = 0
	wait (15)
	script.Parent.ImageTransparency = 0
	wait (0.01)
	script.Parent.ImageTransparency = 0.1
	wait (0.01)
	script.Parent.ImageTransparency = 0.2
	wait (0.01)
	script.Parent.ImageTransparency = 0.3
	wait (0.01)
	script.Parent.ImageTransparency = 0.4
	wait (0.01)
	script.Parent.ImageTransparency = 0.5
	wait (0.01)
	script.Parent.ImageTransparency = 0.6
	wait (0.01)
	script.Parent.ImageTransparency = 0.7
	wait (0.01)
	script.Parent.ImageTransparency = 0.8
	wait (0.01)
	script.Parent.ImageTransparency = 0.9
	wait (0.01)
	script.Parent.ImageTransparency = 1
	wait (0.01)
	script.Parent.Image = script.Parent.Image3.Value
	wait (0.01)
	script.Parent.ImageTransparency = 0.9
	wait (0.01)
	script.Parent.ImageTransparency = 0.8
	wait (0.01)
	script.Parent.ImageTransparency = 0.7
	wait (0.01)
	script.Parent.ImageTransparency = 0.6
	wait (0.01)
	script.Parent.ImageTransparency = 0.5
	wait (0.01)
	script.Parent.ImageTransparency = 0.4
	wait (0.01)
	script.Parent.ImageTransparency = 0.3
	wait (0.01)
	script.Parent.ImageTransparency = 0.2
	wait (0.01)
	script.Parent.ImageTransparency = 0.1
	wait (0.01)
	script.Parent.ImageTransparency = 0
	wait (15)
	script.Parent.ImageTransparency = 0.1
	wait (0.01)
	script.Parent.ImageTransparency = 0.2
	wait (0.01)
	script.Parent.ImageTransparency = 0.3
	wait (0.01)
	script.Parent.ImageTransparency = 0.4
	wait (0.01)
	script.Parent.ImageTransparency = 0.5
	wait (0.01)
	script.Parent.ImageTransparency = 0.6
	wait (0.01)
	script.Parent.ImageTransparency = 0.7
	wait (0.01)
	script.Parent.ImageTransparency = 0.8
	wait (0.01)
	script.Parent.ImageTransparency = 0.9
	wait (0.01)
	script.Parent.ImageTransparency = 1
	wait (0.01)
	end

1 answer

✓ Accepted answer

There is something called CollectionService that makes this pretty easy to do. (CollectionService Reference) Good example of it in use You are able to add tags to parts and interact with them as a whole by using GetTagged. I made a example code, and I'm not sure if it works or not- but this should give you a general idea of what to do in these types of situations.

local CollectionService = game:GetService("CollectionService")

local TV_Folder = workspace:WaitForChild("TVs") -- get the tv folder
	local TVDecal = 2
	local TVDecalTwo = 1

for i,v in pairs(TV_Folder:GetChildren()) do -- Give all the tv's a collection tag
	CollectionService:AddTag(v, "TV_Effect")
end

for i,v in pairs(CollectionService:GetTagged("TV_Effect")) do
	local Thread = coroutine.create(function(v))
		while wait() do
			local ImageLabel = v.HamptomScreen.SurfaceGui.Outer.ImageLabel
			ImageLabel.Image = TVDecal
			ImageLabel.ImageTransparency = 1
			repeat 
				ImageLabel.ImageTransparency = ImageLabel.ImageTransparency -0.1
				wait(0.01)
			until v.HamptomScreen.SurfaceGui.Outer.ImageLabel.ImageTransparency <= 0
			repeat 
				ImageLabel.ImageTransparency = ImageLabel.ImageTransparency + 0.1
				wait(0.01)
			until v.HamptomScreen.SurfaceGui.Outer.ImageLabel.ImageTransparency >= 1
			-- second img
			ImageLabel.Image = TVDecalTwo
			repeat 
				ImageLabel.ImageTransparency = ImageLabel.ImageTransparency -0.1
				wait(0.01)
			until v.HamptomScreen.SurfaceGui.Outer.ImageLabel.ImageTransparency <= 0
			repeat 
				ImageLabel.ImageTransparency = ImageLabel.ImageTransparency +0.1
				wait(0.01)
			until v.HamptomScreen.SurfaceGui.Outer.ImageLabel.ImageTransparency >= 1
		end
	end)
	coroutine.resume(Thread, v)
end

Coroutine is somewhat confusing to some people, and that's fine; There is many ways of doing these things. But essentially I'm creating a new thread for each TV which acts out the script on its own.

If this helped any, please accept this answer.

2 comments

0

Thank you so much, legosweat! This was very helpful. I'm not sure how to accept your answer though.

0

To accept the answer you will have an option that will say ??Accept answer where can you find it? You will see after all comments of this answer it will say ?? report or ?? Accept answer then choose accept answer and your done!

This discussion is preserved as it was. New answers, comments, and votes are closed.