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

why does only part of this script work?

e = script.Parent:GetChildren()
for i,v in pairs(e) do
v.Touched:connect(function(hit)
	if hit.Parent.Humanoid ~= nil
	then v.BrickColor = BrickColor.new("Really black")
	for i=1,10 do
		wait()
		print(i)
		v.Transparency = v.Transparency - .1
		end
end
end)
end
-- everything works but the transparency.

im trying to make it that when a part in a model is touched, it turns black and goes transparent. it does go black. but the transparency loop doesnt work.

3 answers

✓ Accepted answer

There are a couple of issues with it.

e = script.Parent:GetChildren()

for i,v in pairs(e) do
	if v.Name ~= "Script" then -- Change this to whatever your script is called. Necessary to not throw an error because Touched isn't a member of scripts.
		v.Touched:connect(function(hit)
			if hit.Parent.Humanoid ~= nil then
				v.BrickColor = BrickColor.new("Really black")
				for i = 0,1,.1 do
					wait()
					print(i)
					v.Transparency = i -- If you're doing a for loop you might as well use it. What you were doing could've been done with a repeat. If you want to keep this the way you had it, change the negative sign to a plus sign, as 0 is opaque and 1 is transparent, not vice versa.
        		end
			end
		end)
	end
end

Hope this helped.

3 comments

0

You may also want to add a check if the item is a part, depending on where this script is located.

0

thank you

0

No problem.

local debounce = true
for i,v in pairs(script.Parent:GetChildren()) do
	v.Touched:connect(function(hit)
		if hit.Parent.Humanoid and debounce == true then
			debounce =false
			v.BrickColor = BrickColor.new("Really black")
				for i=1,10,0.1 do
					print(i)
					v.Transparency = i
				end
			debounce = true
		end
	end)
end

1 comment

0

Won't this still attempt to set the transparency to 10 (and start at 1), while the max transparency is 1?

You need to tell us what your trying to do. There are a lot of possibilities of what you could be trying to make.

1 comment

0

ok edited

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