You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
im trying to return a popup gui that gives an error message of ‘not enough coins!’
What is the issue? Include screenshots / videos if possible!
ServerScriptService.TeleportPlayerWithCoins:46: attempt to index nil with ‘PlayerGui’ - Server - TeleportPlayerWithCoins:46
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
most info im finding seems to be pre 2021 on forums and Dr Google. i’m sure its simple but its had me stumped for a few hours!
the entire script works great, teleports players if they have enough coins in leaderstats etc, stops them from teleporting if below the required amount but id like to get this popup working to let players know they need to collect more coins.
Code has been butchered from an OnTouch script to work as firing on function IfElse
else
local Popup = game.Workspace.Teleports.HappyTeleOUT.OUT.PopupGUI
local Ready = false
local player = game.Players.LocalPlayer
local playerGui = player.PlayerGui:WaitForChild()
local c = Popup:clone()
c.Parent = playerGui.new
wait(2)
c:remove()
wait(1)
Ready = true
end
end
Alright, well this part has to be changed to this and a lot of the time you want to place these things at the top of the local script since you dont need to call it more than once
local players = game:GetService("Players")
local player = players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")
Also the error code says it coming from the server, so make sure its in a local script.
If it isn’t in a local script then
local players = game:GetService("Players")
local Character = -- Get the character
local player = players:GetPlayerFromCharacter(Character)
local playerGui = player:WaitForChild("PlayerGui")
There are many errors in the code you have provided that may not mean much but could be your problem.
What child are you trying to grab? You have nothing there. Replace it with
local playerGui = player:WaitForChild("PlayerGui")
:remove is not a thing. You need to do c:Destroy() instead.
Also, replace wait with task.wait. Original wait is deprecated.
This might not be a problem, but replace it with :Clone() instead of :clone().
I notice as well this seems to be a local script yet the error you provided is from the server. Can you send the server script and indicate what is line 46? Thanks! If this is a server script, you cannot do game.Players.LocalPlayer since it is a server script. You must find another way (remote events may help!)
and well caught on the serverscript bit - you are absolutely correct it is a server script after all, that’ll teach me to think before i type.
Now this is lending itself to a further issue:
ServerScriptService.TeleportPlayerWithCoins:3: attempt to index nil with ‘PlayerGui’ - Server - TeleportPlayerWithCoins:3
local Players = game:GetService("Players")
local Player = game.Players.LocalPlayer
local PlayerGUI = Player.PlayerGui:WaitForChild("PlayerGui")
local TeleportService = game:GetService("TeleportService")
local happyTeleIN = game.Workspace.Teleports.HappyTeleIN
Yep its still in the server, you can’t get the localplayer in the server, you have to do it by either getting the character or finding another way of referencing your player.
I’d recommend moving the script into a local script inside of playergui or to get the player inside a script in the serverscriptservice you have to use
Player.PlayerAdded
Teleports won’t work on the localscript though, so you should only do it for anything with the UI