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

How to detect when player enters game?

I am trying to create a script that will run when a player enters the game. I have searched for many tutorials but most are not working. Help would be appreciated. This is what I currently have:

player.CharacterAdded:connect(function(character)

script.Parent.BackgroundTransparency = 0.1
wait(0.1)
script.Parent.BackgroundTransparency = 0.2
wait(0.1)
script.Parent.BackgroundTransparency = 0.3
wait(0.1)
script.Parent.BackgroundTransparency = 0.4
wait(0.1)
script.Parent.BackgroundTransparency = 0.5
wait(0.1)
script.Parent.BackgroundTransparency = 0.6
wait(0.1)
script.Parent.BackgroundTransparency = 0.7
wait(0.1)
script.Parent.BackgroundTransparency = 0.8
wait(0.1)
script.Parent.BackgroundTransparency = 0.9
wait(0.1)
script.Parent:Remove()

Also, if you are wondering, this script is to fade out a text box.

6 comments

0

is it a Normal Script or a LocalScript?

0

This is a normal script

0

Try researching your issue before coming here.

0

I did that. None of the articles/videos helped.

0

No, you didn't. You can literally paste your query into a search engine and you get what you need as a first result.

0

Tell me what I need to paste to get a good answer. I have tried searching that. Not much is helpful.

4 answers

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		script.Parent.BackgroundTransparency = 0.1
		wait(0.1)
		script.Parent.BackgroundTransparency = 0.2
		wait(0.1)
		script.Parent.BackgroundTransparency = 0.3
		wait(0.1)
		script.Parent.BackgroundTransparency = 0.4
		wait(0.1)
		script.Parent.BackgroundTransparency = 0.5
		wait(0.1)
		script.Parent.BackgroundTransparency = 0.6
		wait(0.1)
		script.Parent.BackgroundTransparency = 0.7
		wait(0.1)
		script.Parent.BackgroundTransparency = 0.8
		wait(0.1)
		script.Parent.BackgroundTransparency = 0.9
		wait(0.1)
		script.Parent:Remove()
	end)
end)

That should work.

game.Players.PlayerAdded

This fires when a player joins the game.

EDIT: Nvm, just realised you wanted UI to be transparent, sorry.

11 comments

0

It is not working for me, unfortunatly. I am not sure why.

0

Did it give you an error?

0

I checked the output, there does not seem to be any error.

0

Ah, I see the problem. "BackgroundTransparency" is not a property, the property to change transparency is just called "Transparency" with 0 being opaque and 1 being transparent. Hope this helps

0

Yep, just tried it, works. the brick fades from opaque to transparent.

0

BackgroundTransparency is a property for UI. Transparency is a property for parts. I think he was working with UI, DaysWeeksAndMonths.

0

Yep, sorry just realised that from reading the post.

0

I did my answer before you updated yours.

0

ok...?

0

I said that so he would understand I answered it first, correctly. Then he would accept my answer.

0

Alright, I know he's not gonna accept mine, rightly so, I got it wrong.

First, you will have to put a script in Workspace.

Put this code in the script:

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player)
	wait() --DO NO REMOVE THIS WAIT
local UIElement = player.PlayerGui.ScreenGui.Frame.TextLabel --player.PlayerGui is game.StarterGui
UIElement.BackgroundTransparency = 0.1
wait(0.1)
UIElement.BackgroundTransparency = 0.2
wait(0.1)
UIElement.BackgroundTransparency = 0.3
wait(0.1)
UIElement.BackgroundTransparency = 0.4
wait(0.1)
UIElement.BackgroundTransparency = 0.5
wait(0.1)
UIElement.BackgroundTransparency = 0.6
wait(0.1)
UIElement.BackgroundTransparency = 0.7
wait(0.1)
UIElement.BackgroundTransparency = 0.8
wait(0.1)
UIElement.BackgroundTransparency = 0.9
wait(0.1)
UIElement:Remove()
end)

Find player.PlayerGui.ScreenGui.UIElement

Change UIElement to the name of the UIElement in your ScreenGui Do not change player.PlayerGui, player.PlayerGui is game.StarterGui. Using game.StarterGui will not work.

If you have any questions reply to this answer.

13 comments

0

So I have a Frame that the TextLabel is on, does that mean I have to do "player.PlayerGui.ScreenGui.Frame.TextLabel"? or just "player.PlayerGui.ScreenGui.TextLabel" Also, the TextLabel is my UI Element.

0

player.PlayerGui.ScreenGui.Frame.TextLabel should work.

0

I edited the script so it works for you, and you won't have to change anything.

0

It still did not work. I am pretty sure I have copied everything correctly.

0

Did you click view source?

0

Go to: https://www.roblox.com/library/5182015014/Script and put that in your workspace.

0

Okay, I will try that

0

Unfortunatly, none of those worked.

0

Tell if it works or not.

0

No, It didn't

0

Can you send me a screenshot of your startergui?

0

Yes

0

How am I supposed to send a screenshot?

Change your Script to a LocalScript. Changing this should allow you to detect when players join and when you should change the Background Transparency of the GUI.

Because you didn't outline what the purpose of the script is, I'll assume that PlayerAdded is the best way to do whatever you're doing.

Your code can also be shortened using loops like so:

players = game:GetService("Players")

players.PlayerAdded:Connect(function(player) 
	player.CharacterAdded:Connect(function(character) 
		for i  = 1, 10 do
			script.Parent.BackgroundTransparency = i/10
		end 
	end)
	script.Parent:Destroy()
end)

If I am wrong about the intentions of your code please leave a comment and I can find a solution :)

9 comments

0

Ok, so I changed my script to a Local Script, I wrote the new code in, but the Text Label did not fade when I tested the game.

0

If I may ask, what is your intention for this effect? Is it when someone joins the game their screen fades in?

0

No, when the player joins the game, a screen shows with the title of the game, then after about 10 seconds the screen is supposed to fade out to the actual game. Also, I did not add the "wait(10)" at the beginning so I could test it easier.

0

Just make a localscript inside the gui object and add the wait, before my loop. no need for playeradded :)

0

I want it to only play when the player joins, especially since my game is a combat game, I don't want it appearing every time a player dies.

0

Illuminati I changed my script for you and it works, just put the script in workpace, it will work.

0

Okay

0

If it works please accept my answer.

0

It did not work Dave_Robertson

Okay, this site should help. You're looking for PlayerAdded. You can (optionally!) use it with CharacterAdded, which is actually kind of also a function of PlayerAdded.

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		--code
	end)
end)

Also, it's really not very good to repeat code instead of using loops.

for i = 1,10 do
	--code
end

Change your script to a LocalScript instead, too. Your code should look like this (if you changed it to a localscript):

local textbox = game.Players.LocalPlayer.PlayerGui.ScreenGui.TextBox
for i = 1,10 do
	textbox.Transparency = textbox.Transparency +.1
end

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