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

How to access player's GUI if script is not in starter GUI?

OK, so here's what I wanna do.

  • I have a script that loops music in a specific folder in the workspace.
  • I want to make a credit label appear every time new music starts, and that shows the music name.

Issue: on line 9, I have no idea how to get the current local player, and get a label called "Music Credit Label" in the player's screen GUI

So it's easy to access all the GUI of your player if your script is in ScreenGui because you can simply write:

local label = script.Parent["Music Credit Label"]

aaannddd - DONE. We can use that label and credit the name of each music when it starts!

 -- Table that stores every sound 
 local playlist = game.Workspace["Music Playlist"]:GetChildren()
 
 -- Service that loads music before it starts so it doesn't lag or anything.
 local contentProvider = game:GetService("ContentProvider")
 
 -- his is where I get the problem. I simply want to get the player GUI and store it in this variable.
 local credit =  "I WANT TO GET PLAYERS SCREENGUI"
 
 -- Function that shows the name of the music that just started.
 local function CREDIT(music)
	print("Showing credit..") 
 	credit.Visible = true
 	credit.Text = 'Now playing: '..'"'..music.Name..'"'
 	wait(4)
 	credit.Visible = false
 	print("Hiding credit...")
 end
 
 
 -- For loop that loops the music.
 for index, music in pairs(playlist) do
	contentProvider:PreloadAsync({music})
	music:Play()
 	CREDIT(music)
 	print("Now Playing: ".. music.Name)
 	wait(music.TimeLength)
end

ANY help would be great. It's ok if u can't help.

3 comments

0

if its good u must add first in starter gui then add in the starter gui screen gui and then the label or something else

0

Is this a local script right? So u can just do something like "game.Players.LocalPlayer.PlayerGui"

0

@thaylerfg No, this is a normal script. I don't know the difference between local and normal scripts yet. I am a junior scripter.

2 answers

``local credit = game.Players.LocalPlayer.PlayerGui

1 comment

0

I tried that too! But I got this error: ServerScriptService.Music Manager:4: attempt to index nil with 'PlayerGui' and when I printed "game.Players.LocalPlayer" it was nil

To get a specific player, You can use game.Players.LocalPlayer

For Example:

1.Getting Player Name

local Player = game.Players.LocalPlayer

while true do
	script.Parent.Text = Player.Name
end

2.Getting Player GUI

local Player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function()
	Player.PlayerGui:FindFirstChild("GUI NAME HERE") --Detecting for Specific GUI
end)

Hope It Help!

2 comments

0

My script is ServerScriptServices

0

actually, I change my mind. I won't show credit of the music, its all made by roblox really.. I might add it later when I get more advanced in scripting. But I would still like to know, How to get the player? Because game.Players.LocalPlayer is nil!

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