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

How to fix this fading text module?

local module = {}
 function module.TextFade(plr)
	local CurrentTransparancy = 0
	local PlrUI = game.Players.LocalPlayer.PlayerGui.PlrUI
	for i = 1,100,.1
	do
		CurrentTransparancy = CurrentTransparancy + 1 
		PlrUI.Title.Transparancy = CurrentTransparancy
	end
end
return module

2 answers

Howdy!

You're rapidly increasing the transparency. Remember that a transparency of one is completely gone. Also, you've got a weird way of adding the transparency. Try what I have below.

local module = {}
function module.TextFade(plr)
	local CurrentTransparancy = 0
	local PlrUI = game.Players.LocalPlayer.PlayerGui.PlrUI
	while true do
        	PlrUI.Title.Transparancy = PlrUI.Title.Transparancy + 0.1
		repeat until PlrUT.Title.Transparancy = 1
	end
end
return module

If this helped you out, consider accepting this answer for those sweet, sweet reputation points. If not, comment below and I (or someone else) will help you out.

Be sure to check out the Roblox API Documentation as well for additional reference.

5 comments

0

20:22:33.487 - ServerScriptService.Script.TextsModule:4: attempt to index nil with 'PlayerGui'

0

What is the name of the GUI you're trying to refer to? The error says that "PlrUI" doesn't exist, make sure the name is right.

0

Its not the GUI its refering to its says playergui

0

You need to use :WaitForChild("PlayerGui", 1), since the script is executing before the StarterGui is placed in the PlayerGui.

0

I read it wrong. I would try to use :WaitForChild() to get the PlayerGui because I think it's searching too early for it to appear.

Finding The Errors

local module = {}
 function module.TextFade(plr)
    local CurrentTransparancy = 0
    local PlrUI = game.Players.LocalPlayer.PlayerGui.PlrUI --// Error #1
    for i = 1,100,.1 --// Error #2
    do
        CurrentTransparancy = CurrentTransparancy + 1 --// Error #3
        PlrUI.Title.Transparancy = CurrentTransparancy --// Error #3
    end
end
return module

Error #1 - You already have plr passed through as an argument, and you cannot access LocalPlayer through a ModuleScript.

Error #2 - You are already making it invisible as it's starting at Transparency 1, and going to 100, by 0.1. You have to start it at 0 to make it visible, and the transparency only goes to 1, anything after that is the same as having it at 1.

Error #3 - You are increasing the transparency by 1, instead of using the variable i


Fixed Script

local fadeModule = {}

function module.FadeText(player)
	local playerGui = player:WaitForChild("PlayerGui")
	local UI = playerGui:WaitForChild("PlrUI")
	local title = UI:WaitForChild("Title")

	for i = 0,1,0.1 do
		title.Transparency = i
		game:GetService("RunService").Stepped:Wait() --// This will make it run smoother, better than using wait()
	end
end

return fadeModule

Hope this helped! Feel free to select this as an answer if this worked for you!

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