Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
-1

How to detect when player enters game?

Asked by 3 years ago

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.

0
is it a Normal Script or a LocalScript? TheBigBro122 427 — 3y
0
This is a normal script TheAncientIlluminati -10 — 3y
0
Try researching your issue before coming here. Ziffixture 6913 — 3y
0
I did that. None of the articles/videos helped. TheAncientIlluminati -10 — 3y
View all comments (2 more)
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. Ziffixture 6913 — 3y
0
Tell me what I need to paste to get a good answer. I have tried searching that. Not much is helpful. TheAncientIlluminati -10 — 3y

4 answers

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago
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.

0
It is not working for me, unfortunatly. I am not sure why. TheAncientIlluminati -10 — 3y
0
Did it give you an error? DaysWeeksAndMonths 90 — 3y
0
I checked the output, there does not seem to be any error. TheAncientIlluminati -10 — 3y
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 DaysWeeksAndMonths 90 — 3y
View all comments (7 more)
0
Yep, just tried it, works. the brick fades from opaque to transparent. DaysWeeksAndMonths 90 — 3y
0
BackgroundTransparency is a property for UI. Transparency is a property for parts. I think he was working with UI, DaysWeeksAndMonths. Dave_Robertson 42 — 3y
0
Yep, sorry just realised that from reading the post. DaysWeeksAndMonths 90 — 3y
0
I did my answer before you updated yours. Dave_Robertson 42 — 3y
0
ok...? DaysWeeksAndMonths 90 — 3y
0
I said that so he would understand I answered it first, correctly. Then he would accept my answer. Dave_Robertson 42 — 3y
0
Alright, I know he's not gonna accept mine, rightly so, I got it wrong. DaysWeeksAndMonths 90 — 3y
Ad
Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

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.

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. TheAncientIlluminati -10 — 3y
0
player.PlayerGui.ScreenGui.Frame.TextLabel should work. Dave_Robertson 42 — 3y
0
I edited the script so it works for you, and you won't have to change anything. Dave_Robertson 42 — 3y
0
It still did not work. I am pretty sure I have copied everything correctly. TheAncientIlluminati -10 — 3y
View all comments (9 more)
0
Did you click view source? Dave_Robertson 42 — 3y
0
Go to: https://www.roblox.com/library/5182015014/Script and put that in your workspace. Dave_Robertson 42 — 3y
0
Okay, I will try that TheAncientIlluminati -10 — 3y
0
Unfortunatly, none of those worked. TheAncientIlluminati -10 — 3y
0
Tell if it works or not. Dave_Robertson 42 — 3y
0
No, It didn't TheAncientIlluminati -10 — 3y
0
Can you send me a screenshot of your startergui? Dave_Robertson 42 — 3y
0
Yes TheAncientIlluminati -10 — 3y
0
How am I supposed to send a screenshot? TheAncientIlluminati -10 — 3y
Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

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 :)

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. TheAncientIlluminati -10 — 3y
0
If I may ask, what is your intention for this effect? Is it when someone joins the game their screen fades in? NinjaManChase 226 — 3y
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. TheAncientIlluminati -10 — 3y
0
Just make a localscript inside the gui object and add the wait, before my loop. no need for playeradded :) NinjaManChase 226 — 3y
View all comments (5 more)
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. TheAncientIlluminati -10 — 3y
0
Illuminati I changed my script for you and it works, just put the script in workpace, it will work. Dave_Robertson 42 — 3y
0
Okay TheAncientIlluminati -10 — 3y
0
If it works please accept my answer. Dave_Robertson 42 — 3y
0
It did not work Dave_Robertson TheAncientIlluminati -10 — 3y
Log in to vote
0
Answered by
sngnn 274 Moderation Voter
3 years ago
Edited 3 years ago

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

Answer this question