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

i want to make a gui appear when teleported but the gui doesnt appear, how do i do it?

It's NOT a localscript the error code: attempt to index nil with 'PlayerGui'

The script

function onClicked()

	local c = game.Players:GetChildren()
	for i = 1, #c do
		c[i].Character.UpperTorso.CFrame = CFrame.new(script.Parent.Parent.Teleport.Position)
	end
	
	player.PlayerGui.Tasksbar.t1.Visible = true -- the gui
	player.PlayerGui.Tasksbar.t2.Visible = true -- gui
	player.PlayerGui.Tasksbar.t3.Visible = true -- gui

end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

####Re-edited by JesseSong!

7 comments

0

Well, you have not shown how you are assigning player variable.

0

Player has not been referenced.

0

You can check your previous question which has been answered effectively by me here https://scriptinghelpers.org/questions/114769/attempt-to-index-nil-with-playergui-how-do-i-fix-it

0

ClickDetector mouseClick event returns player who clicked as it's first argument, you can just do function onClicked(player)

0

You can use function onClicked(player) since mouseclick event returns a player, but you need to reference the player if you want to do other tasks other than a clickdetector.

0

After realising your vigorous  mistakes, I've noticed that this is not a localscript GUI's only run on the local player's client, therefore the whole script is incorrect. Also you need to define the player variable e.g. local player = game.Players.LocalPlayer

0

so how do i do it

2 answers

The problem is that the variable "player" isn't defined. There are several ways to get the player, there is 1 main one for the server and another one for the client, to access the player on the server you can add a players.PlayerAdded event to your code, or if the code is on the client use game.Players.LocalPlayer. Also I recommend not using :connect since it's deprecated use :Connect instead.

You don't have player properly defined, fix:

function onClicked()

    local c = game.Players:GetChildren()
    for i = 1, #c do
        c[i].Character.UpperTorso.CFrame = CFrame.new(script.Parent.Parent.Teleport.Position)
 c[i].PlayerGui.Tasksbar.t1.Visible = true -- the gui
 c[i].PlayerGui.Tasksbar.t2.Visible = true -- gui
 c[i].PlayerGui.Tasksbar.t3.Visible = true -- gui

    end

   
end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

Because you're getting a table of players and referencing an index for each player, therefore c[i] represents the current player, so you can adjust each gui like that.

7 comments

0

it doesnt work, Tasksbar is not a valid member of PlayerGui "Players.IIPedroI.PlayerGui" but i dont get it, it is in the playergui

0

did you put the taskbar gui into playergui via a localscript? if you did it loads it only for the client and when you try to reference it from a server script it won't exist

0

no, it is in startergui that goes to playergui right?

0

yes, is taskbars parent like a screengui?

0

yes

0

then u need to say PlayerGui.SCREENGUINAME.Taskbar

0

so i need to create another screengui

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