I don’t know why I’m reciving this error. Everything works in the LocalScript but it still returns it.
Error: 16:09:46.363 - Players.Jermartynojm.PlayerGui.PlayerList.CheckIfPlayerIsOnMobile:6: attempt to index nil with ‘Parent’
Local Script Inside GUI:
while true do
repeat wait() until game.Players.LocalPlayer.CharacterAdded
local UIS = game:GetService("UserInputService")
local GuiService = game:GetService("GuiService")
if UIS.TouchEnabled and not UIS.KeyboardEnabled and not UIS.MouseEnabled and not UIS.GamepadEnabled and not GuiService:IsTenFootInterface() then
local GUI = script.Parent.Parent.Parent:WaitForChild("PlayerGui")
local Weapons = GUI:WaitForChild("Weapons")
Weapons.OpenWeaponsInfo.Position = UDim2.new(0.93,0,0.3,0)
local TurnInvisible = GUI:WaitForChild("TurnInvisible")
TurnInvisible.TurnPlayerInvisible.Position = UDim2.new(0.93,0,0.5,0)
local Inventory = GUI:WaitForChild("Inventory")
Inventory.OpenInventory.Position = UDim2.new(0.93,0,0.5,0)
local MobileModeSurvivalsCounter = GUI:WaitForChild("MobileModeSurvivalsCounter")
MobileModeSurvivalsCounter.SurvivalsCounter.Visible = true
local PlayerList = GUI:WaitForChild("PlayerList")
PlayerList:Destroy()
end
end
That’s it. I hope that somebody will help.
It’s a LocalScript, right? You can get the PlayerGui from LocalPlayer;
local plr = game.Players.LocalPlayer
local GUI = plr:WaitForChild("PlayerGui")
local Weapons = GUI:WaitForChild("Weapons")
local TurnInvisible = GUI:WaitForChild("TurnInvisible")
local Inventory = GUI:WaitForChild("Inventory")
local MobileModeSurvivalsCounter = GUI:WaitForChild("MobileModeSurvivalsCounter")
local PlayerList = GUI:WaitForChild("PlayerList")
local UIS = game:GetService("UserInputService")
local GuiService = game:GetService("GuiService")
while true do
repeat wait() until game.Players.LocalPlayer.CharacterAdded
if UIS.TouchEnabled and not UIS.KeyboardEnabled and not UIS.MouseEnabled and not UIS.GamepadEnabled and not GuiService:IsTenFootInterface() then
Weapons.OpenWeaponsInfo.Position = UDim2.new(0.93,0,0.3,0)
TurnInvisible.TurnPlayerInvisible.Position = UDim2.new(0.93,0,0.5,0)
Inventory.OpenInventory.Position = UDim2.new(0.93,0,0.5,0)
MobileModeSurvivalsCounter.SurvivalsCounter.Visible = true
PlayerList:Destroy()
end
end
I also recommend you just assign variables outside of the for loop.
Thanks for the help, but how will you fix this if I don’t want to use wait()?
Script to fix:
local plr = game.Players.LocalPlayer
local GUI = plr:WaitForChild("PlayerGui")
local UIS = game:GetService("UserInputService")
local GuiService = game:GetService("GuiService")
local function GUI()
if UIS.TouchEnabled and not UIS.KeyboardEnabled and not UIS.MouseEnabled and not UIS.GamepadEnabled and not GuiService:IsTenFootInterface() then
local Weapons = GUI:WaitForChild("Weapons")
Weapons.OpenWeaponsInfo.Position = UDim2.new(0.93,0,0.3,0)
local TurnInvisible = GUI:WaitForChild("TurnInvisible")
TurnInvisible.TurnPlayerInvisible.Position = UDim2.new(0.93,0,0.5,0)
local Inventory = GUI:WaitForChild("Inventory")
Inventory.OpenInventory.Position = UDim2.new(0.93,0,0.5,0)
local MobileModeSurvivalsCounter = GUI:WaitForChild("MobileModeSurvivalsCounter")
MobileModeSurvivalsCounter.SurvivalsCounter.Visible = true
local PlayerList = GUI:WaitForChild("PlayerList")
PlayerList:Destroy()
end
end
plr.CharacterAdded:Connect(GUI)
You can use game:GetService(“RunService”).RenderStepped
RenderStepped fires every frame rendered on the client.
game:GetService("RunService").RenderStepped:Connect(function()
--code here
end)
1 Like