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

How to use playerAdded for ScreenGui fade?

Asked by 2 years ago

So basically I have a script that greets player with black screen when he joins but soon after becomes transparent. It works in StarterGui but it really problematic in editor because it is visible. I want to use the PlayerAdded so that the ScreenGui is put in Players.LocalPlayer.PlayerGui but I have problems with it. Excuse me for my horrible sentencing.

script:

local Players = game:GetService("Players")
local gui = Players.LocalPlayer.PlayerGui
local blink = game:GetService("ServerStorage"):GetChildren("blink")

Players.PlayerAdded:Connect(function()
    blink:Clone(gui)
end)

error that comes with game start:

ServerScriptService.blinker:2: attempt to index nil with 'PlayerGui'  -  Server - blinker:2
Stack Begin  -  Studio
Script 'ServerScriptService.blinker', Line 2  -  Studio - blinker:2
Stack End  -  Studio
0
Is the script you are using a LocalScript or a normal Script? lrd14 0 — 2y

1 answer

Log in to vote
0
Answered by
3F1VE 257 Moderation Voter
2 years ago

I saw your mistakes. You put :Clone(gui) AND you used :GetChildren("blink")

local Players = game:GetService("Players")
local gui = Players.LocalPlayer.PlayerGui
local blink = game:GetService("ReplicatedStorage"):WaitForChild("blink") -- Use `Instance:WaitForChild(childName) instead (clients dont have access to ServerStorage so I would recommend moving the gui to ReplicatedStorage which both the server and client have access to.)

Players.PlayerAdded:Connect(function()
    local Clone - blink:Clone() -- A clone creates a new copy of an instance, this can be defined as a variable or done 2 ways
Clone.Parent = gui
--blink:Clone().Parent = gui -- most simplest way
end)
Ad

Answer this question