This script includes Tweens to animate buttons and frames, but the function does not work.
local Players = game:GetService('Players')
local StarterGui = game:GetService('StarterGui')
local TweenService = game:GetService('TweenService')
local BlackFrame = StarterGui.MenuGUI:WaitForChild('BlackFrame')
local SpaceButton = StarterGui.MenuGUI:WaitForChild('SpaceButton')
local DawnTeam = StarterGui.MenuGUI.BlackFrame:WaitForChild('TextLabel')
local ButtonTweenInfo = TweenInfo.new(
1,
Enum.EasingStyle.Quad,
Enum.EasingDirection.InOut,
0,
false
)
local TextTween1 = TweenService:Create(DawnTeam,ButtonTweenInfo, {TextTransparency = 0})
local TextTween2 = TweenService:Create(DawnTeam,ButtonTweenInfo, {TextTransparency = 1})
local FrameTween1 = TweenService:Create(BlackFrame,ButtonTweenInfo, {BackgroundTransparency = 1})
local SpaceButtonTween1 = TweenService:Create(SpaceButton,ButtonTweenInfo, {BackgroundTransparency = 0})
function PlayerAdded(plr)
BlackFrame.Visible = true -- problem starts from here
print('Player added') -- prints successfully
wait(3)
TextTween1:Play()
wait(3)
TextTween2:Play()
wait(0.5)
FrameTween1:Play()
print('Done') -- prints successfully
end
game.Players.PlayerAdded:Connect(PlayerAdded)
for i,v in next,game.Players:GetPlayers() do
PlayerAdded(v)
end
There is no errors at output, it is just Frame does not become visible and Tweens do not work.
You’re not referencing the correct GUI instance. StarterGui is merely a storage container for the game’s UI, and is not where the active UI of a client resides.
“When a Player.Character spawns, the contents of their PlayerGui (if any) are emptied. Children of the StarterGuiare then copied along with their descendants into the PlayerGui. Note, however, that LayerCollector objects such as ScreenGuis with their ResetOnSpawn property set to false will only be placed into each player’s PlayerGui once and will not be deleted when the Player respawns.”
You must access the client’s PlayerGui folder instead
Another note
You should be scripting your UI via a LocalScript. The server should never be manipulating GUI instances. The LocalScript should be placed within the GUI itself, or StarterPlayerScripts with correct references to the to-be-manipulated GUI instances. I assume this is a welcoming GUI, so you’ll want to disable ScreenGui.ResetOnSpawn. Remove any code to do with detecting players joining as the LocalScript begins executing as soon as it’s downloaded by the newly connected client
As I said, the LocalScript beings executing as soon as it’s downloaded by the newly connected client. You can imagine your entire script as the body of a function connected to Players.PlayerAdded