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