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

My script should lower the transparency of parts by 0.1 for every half a second, but it won't work?

I have a script that when a button is clicked it takes the transparency down by 0.1 until the transparency equals 0 every half a second, but it just stops at 0.9, help?

local button = workspace.button.ClickDetector
local sign = workspace.sign.SurfaceGui.TextLabel
local cover = workspace.cover:GetChildren()
local tower = workspace.tower:GetChildren()

local covertransparency = 1
local button2 = game.Workspace.button2.ClickDetector

for i,v in pairs(tower) do
	local towertransparency = 1
	button.MouseClick:Connect(function (onclicked)
		repeat
			v.Transparency = towertransparency - 0.1
		until v.Transparency == 0
		
	end)
end

Note: This is only part of the script, ignore the sign and cover variables.

2 comments

0

the towertransparency always stays at 1 as it doesn't change. Also, this doesn't lower the transparency of parts by 0.1 every half a second but rather almost immediatly due to this script not having an wait(0.5) function

0

I added in the wait funtion, but what do I change towertransparency too?

2 answers

Hello, BabyHades_2!

• Events don't need to be inside a loop to run

• You can use the part's transparency to remove 0.1

local button = workspace.button.ClickDetector
local sign = workspace.sign.SurfaceGui.TextLabel
local cover = workspace.cover:GetChildren()
local tower = workspace.tower:GetChildren()

local covertransparency = 1
local button2 = game.Workspace.button2.ClickDetector

button.MouseClick:Connect(function (onclicked)
    for i,v in pairs(tower) do -- I didn't understood why this loop was outside of the click detector
        repeat
            v.Transparency = v.Transparency - 0.1 -- Why not just using the part's transparency?
            wait(0.5) --Don't forget the wait
        until v.Transparency == 0
    end
end)

2 comments

0

Tower is a model, not a part, so I did :getchildren for a table

0

I know, but the loop was making the event(mouse click) be called lots of times, it should be inside the event

#Introduction

Hey there pal!

I see there's an issue with your transparency thing.

Let's start!

#Scripting

If you didn't know, for loops can be utilized into fading scripts.

for i = 0,1,0.1 do
	script.Parent.Transparency = i
	wait(0.1) --Increment
end

To reverse this...

for i = 1,0,-0.1 do
	script.Parent.Transparency = i
	wait(0.1)
end

Now, try using it in your script!

button.MouseButton1Click:Connect(function()
	for i = 0,1,0.1 do
		tower.Transparency = i
		wait(0.1)
	end
end)

#Conclusion

Hope I helped! Have a nice day!

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