ScreenGui not found but exist

I am getting the error that a screen GUI does not exist but is literally there. I have never had this problem before and can’t find a solution or solve the issue. If that makes sense, I am getting the player variable by getting the game LocalPlayer using the Player service.

local Tween = game:GetService("TweenService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer

local changeEvent = game.ReplicatedStorage:WaitForChild("ChangePlayerCharacter")

local charsFolder = game.ReplicatedStorage:WaitForChild("Characters")

local ShopBtn = player.PlayerGui.GameGui:FindFirstChild("ShopBtn")
local NukeBtn = player.PlayerGui.GameGui:FindFirstChild("NukeBtn")
local BackToMenu = player.PlayerGui.GameGui:FindFirstChild("BackToMenu")

local ShopBtnOut = Tween:Create(ShopBtn, TweenInfo.new(0.4, Enum.EasingStyle.Quad, Enum.EasingDirection.Out),{Position = UDim2.new(-0, 0,0.939, 0)})

local NukeBtnOut = Tween:Create(NukeBtn, TweenInfo.new(0.4, Enum.EasingStyle.Quad, Enum.EasingDirection.Out),{Position = UDim2.new(0, 0,0.854, 0)})

local BackToMenuOut = Tween:Create(BackToMenu, TweenInfo.new(0.4, Enum.EasingStyle.Quad, Enum.EasingDirection.Out),{Position = UDim2.new(0.112, 0,0.939, 0)})

changeEvent.OnServerEvent:Connect(function(player,chosenCharacter)
	if charsFolder:FindFirstChild(chosenCharacter) then
		local newChar = charsFolder:FindFirstChild(chosenCharacter):Clone()
		local plrChar = player.Character
		
		if newChar:FindFirstChild("HumanoidRootPart") then
			newChar.PrimaryPart = newChar.HumanoidRootPart
			newChar:SetPrimaryPartCFrame(plrChar.HumanoidRootPart.CFrame)
		elseif newChar:FindFirstChild("Torso") and not newChar:FindFirstChild("HumanoidRootPart") then
			newChar.PrimaryPart = newChar.Torso
			newChar:SetPrimaryPartCFrame(plrChar.Torso.CFrame)
			game.Players.LocalPlayer.character.LowerTorso.CFrame = CFrame.new(workspace.tp.position)
		end
		
		newChar.Name = player.Name
		player.Character = newChar

		local rootPart = newChar:FindFirstChild("HumanoidRootPart") or newChar:FindFirstChild("Torso")
		local plrRoot = player.Character:FindFirstChild("HumanoidRootPart") or player.Character:FindFirstChild("Torso")

		if rootPart and plrRoot then
			rootPart.CFrame = plrRoot.CFrame
		end

		newChar.Parent = workspace
		newChar.LowerTorso.CFrame = CFrame.new(workspace.tp.Position)
		
		newChar.Zombie.Died:Connect(function()
			print("zombie died")
			game.StarterGui:SetCoreGuiEnabled("All", true)
			game.StarterGui:SetCoreGuiEnabled("PlayerList", false)
			ShopBtnOut:Play()
			NukeBtnOut:Play()
			BackToMenuOut:Play()
		end)
	else
		warn("character doesnt exist or something went wrong.")
	end
end)

Error I am receiving;
image

Try this:

local Tween = game:GetService("TweenService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer

repeat task.wait() until player:FindFirstChild("PlayerGui")
local changeEvent = game.ReplicatedStorage:WaitForChild("ChangePlayerCharacter")

local charsFolder = game.ReplicatedStorage:WaitForChild("Characters")

local ShopBtn = player.PlayerGui:WaitForChild("GameGui"):FindFirstChild("ShopBtn")
local NukeBtn = player.PlayerGui:WaitForChild("GameGui"):FindFirstChild("NukeBtn")
local BackToMenu = player.PlayerGui:WaitForChild("GameGui"):FindFirstChild("BackToMenu")

local ShopBtnOut = Tween:Create(ShopBtn, TweenInfo.new(0.4, Enum.EasingStyle.Quad, Enum.EasingDirection.Out),{Position = UDim2.new(-0, 0,0.939, 0)})

local NukeBtnOut = Tween:Create(NukeBtn, TweenInfo.new(0.4, Enum.EasingStyle.Quad, Enum.EasingDirection.Out),{Position = UDim2.new(0, 0,0.854, 0)})

local BackToMenuOut = Tween:Create(BackToMenu, TweenInfo.new(0.4, Enum.EasingStyle.Quad, Enum.EasingDirection.Out),{Position = UDim2.new(0.112, 0,0.939, 0)})

changeEvent.OnServerEvent:Connect(function(player,chosenCharacter)
	if charsFolder:FindFirstChild(chosenCharacter) then
		local newChar = charsFolder:FindFirstChild(chosenCharacter):Clone()
		local plrChar = player.Character
		
		if newChar:FindFirstChild("HumanoidRootPart") then
			newChar.PrimaryPart = newChar.HumanoidRootPart
			newChar:SetPrimaryPartCFrame(plrChar.HumanoidRootPart.CFrame)
		elseif newChar:FindFirstChild("Torso") and not newChar:FindFirstChild("HumanoidRootPart") then
			newChar.PrimaryPart = newChar.Torso
			newChar:SetPrimaryPartCFrame(plrChar.Torso.CFrame)
			game.Players.LocalPlayer.character.LowerTorso.CFrame = CFrame.new(workspace.tp.position)
		end
		
		newChar.Name = player.Name
		player.Character = newChar

		local rootPart = newChar:FindFirstChild("HumanoidRootPart") or newChar:FindFirstChild("Torso")
		local plrRoot = player.Character:FindFirstChild("HumanoidRootPart") or player.Character:FindFirstChild("Torso")

		if rootPart and plrRoot then
			rootPart.CFrame = plrRoot.CFrame
		end

		newChar.Parent = workspace
		newChar.LowerTorso.CFrame = CFrame.new(workspace.tp.Position)
		
		newChar.Zombie.Died:Connect(function()
			print("zombie died")
			game.StarterGui:SetCoreGuiEnabled("All", true)
			game.StarterGui:SetCoreGuiEnabled("PlayerList", false)
			ShopBtnOut:Play()
			NukeBtnOut:Play()
			BackToMenuOut:Play()
		end)
	else
		warn("character doesnt exist or something went wrong.")
	end
end)

It doesn’t work with FindFirstChild I am guessing

Edit; this is also a script, not a local script if that helps

You cannot use LocalPlayer on a server script. That is why it is not finding the ScreenGui. You should always be updating guis on the client anyway, there is almost never a practical reason for the server to be updating guis

Alright, thanks for the information.

This isn’t a local script though, it is a script.

If it isn’t a localscript why are you using local player = Players.LocalPlayer?
`

1 Like

I am not quite sure now. Thanks for asking.

1 Like