Here's the code:
function onPlayerEntered (swag) local GUI = script.Parent.Parent GUI.Parent = swag.PlayerGui wait(5) GUI.BackgroundTransparency = 0.1 wait(0.1) GUI.BackgroundTransparency = 0.2 wait(0.1) GUI.BackgroundTransparency = 0.3 wait(0.1) GUI.BackgroundTransparency = 0.4 wait(0.1) GUI.BackgroundTransparency = 0.5 wait(0.1) GUI.BackgroundTransparency = 0.6 wait(0.1) GUI.BackgroundTransparency = 0.7 wait(0.1) GUI.BackgroundTransparency = 0.8 wait(0.1) GUI.BackgroundTransparency = 0.9 wait(0.1) GUI.BackgroundTransparency = 1 GUI.Active = false game.Players.ChildAdded:connect (onPlayerEntered) end
Doesn't give me errors, but it won't fade like it should.
Your problem is that the event isn't connecting to the function properly. It's inside of the function which never gets called, so it doesn't ever connect to it.
To fix this, we simply need to move the connection outside of the function like so: (Put this in a LocalScript)
local GUI = script.Parent.Parent wait(5) for i=0,1,.1 do --Same thing for fading, just requires much less lines. More efficient :P GUI.BackgroundTransparency = i wait(0.1) end GUI.Active = false
Ok, so I believe it should work properly now.
If you have any further problems/questions, please leave a comment below, and I'll see what I can do. Hope I helped :P
You should always place your connection line outside of the function block, And lines 8-26 can be shortened if a for
loop is used.
A For loop?
A for
loop has an iterator that is supposed to keep track on how many times the for loop is to run, for Instance.
for iterator = begin, last , increment do -- the begin is where the value must start, the last is where the value must end, and increment is the amount of decrease/increase. for i = 1, 5, 1 do wait(1) print("Amount of Seconds remaining "..i) end -- > Amount of Seconds remaining 1 , Amount of Seconds remaining 2. Etc.
function onPlayerEntered(swag) local GUI = script.Parent.Parent GUI.Parent = swag:WaitForChild("PlayerGui") wait(5) for i = .1, 1 ,.1 do wait() GUI.BackgroundTransparency = i end GUI.Active = false end game.Players.PlayerAdded:connect(onPlayerEntered)