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

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

Asked by 4 years ago
Edited by JesseSong 4 years ago

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!

0
Well, you have not shown how you are assigning player variable. BestCreativeBoy 1395 — 4y
0
Player has not been referenced. JesseSong 3916 — 4y
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 JesseSong 3916 — 4y
0
ClickDetector mouseClick event returns player who clicked as it's first argument, you can just do function onClicked(player) imKirda 4491 — 4y
View all comments (3 more)
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. JesseSong 3916 — 4y
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 JesseSong 3916 — 4y
0
so how do i do it IIPedroI -3 — 4y

2 answers

Log in to vote
0
Answered by
birds3345 177
4 years ago

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.

Ad
Log in to vote
0
Answered by
Robowon1 323 Moderation Voter
4 years ago

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.

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 IIPedroI -3 — 4y
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 Robowon1 323 — 4y
0
no, it is in startergui that goes to playergui right? IIPedroI -3 — 4y
0
yes, is taskbars parent like a screengui? Robowon1 323 — 4y
View all comments (3 more)
0
yes IIPedroI -3 — 4y
0
then u need to say PlayerGui.SCREENGUINAME.Taskbar Robowon1 323 — 4y
0
so i need to create another screengui IIPedroI -3 — 4y

Answer this question