Gui Doesn't Open in Roblox (but in Roblox Studio Yes)

Hello everyone, so yesterday I made a shop gui that opens when I thouch a part and then it closes when you press the close button. So everything is working well. But when I try the Gui in roblox it doesnt work, the Gui doesnt open. But in Roblox Studio (while Testing) it works 100%.

If anyone could help me id really appreciate, thx!

1 Like

It would be nice if you could at least provide the code you used for the shop gui

1 Like

Join your Roblox game. Then press ‘F9’ button, see what any error here.

1 Like
--Variables

local open = game.Workspace.openPart
local close = game.Workspace.closePart
local frame = script.Parent
local closeButton = frame.closeButton

local buy_1 = frame.buy1
local buy_2 = frame.buy2
local buy_3 = frame.buy3
local buy_4 = frame.buy4
local buy_5 = frame.buy5
local buy_6 = frame.buy6
local buy_7 = frame.buy7
local buy_8 = frame.buy8


local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild('BuyTool')

--Script

frame.Visible = false

local function shopMenu(otherPart)
	local player = game.Players:FindFirstChild(otherPart.Parent.Name)
	if player then
		player.PlayerGui.ScreenGui.Shop.Visible = true
		player.Character.Humanoid.WalkSpeed = 0
	end
end

local function closeMenu()
	local player = game.Players.LocalPlayer
	player.PlayerGui.ScreenGui.Shop.Visible = false
	player.Character.HumanoidRootPart.CFrame = CFrame.new(close.Position.X,close.Position.Y + 3,close.Position.Z)
	player.Character.Humanoid.WalkSpeed = 16
end

--ToolsScript

local function buyTool1()
	local tool = ReplicatedStorage.ShopItems.ClassicSword
	remoteEvent:FireServer(tool)
	
end

local function buyTool2()
	local tool = ReplicatedStorage.ShopItems.ClassicPaintballGun
	remoteEvent:FireServer(tool)
	
end

local function buyTool3()
	local tool = ReplicatedStorage.ShopItems.ClassicTimebomb
	remoteEvent:FireServer(tool)
	
end

local function buyTool4()
	local tool = ReplicatedStorage.ShopItems.Autohyperlaser
	remoteEvent:FireServer(tool)
	
end

local function buyTool5()
	local tool = ReplicatedStorage.ShopItems.SpeedCoil
	remoteEvent:FireServer(tool)
	
end

local function buyTool6()
	local tool = ReplicatedStorage.ShopItems.GatlingLaser
	remoteEvent:FireServer(tool)
end

local function buyTool7()
	local tool = ReplicatedStorage.ShopItems.Pikachu
	remoteEvent:FireServer(tool)
	
end

local function buyTool8()
	local tool = ReplicatedStorage.ShopItems.HandlessSegway
	remoteEvent:FireServer(tool)
	
end


--Events

open.Touched:Connect(shopMenu)
closeButton.MouseButton1Click:Connect(closeMenu)


buy_1.MouseButton1Click:Connect(buyTool1)
buy_2.MouseButton1Click:Connect(buyTool2)
buy_3.MouseButton1Click:Connect(buyTool3)
buy_4.MouseButton1Click:Connect(buyTool4)
buy_5.MouseButton1Click:Connect(buyTool5)
buy_6.MouseButton1Click:Connect(buyTool6)
buy_7.MouseButton1Click:Connect(buyTool7)
buy_8.MouseButton1Click:Connect(buyTool8)

1 Like

Do you have multiple instances in StarterGui named “ScreenGui”?

no, just one, and its this one

You could instead try using game.Players:GetPlayerFromCharacter() or game.Players[hit.Parent.Name]

Althought game.Players[hit.Parent.Name] would probably cause a lot of errors and problems

Assuming the localscript is parented to the same ScreenGui as the Shop frame which you’re trying to index, why don’t you refer to the same Gui by defining something like

-- at the start of the script
local ScreenGui = script:FindFirstAncestorWhichIsA("ScreenGui") 

-- in the function
ScreenGui.Shop.Visible = true

instead of
player.PlayerGui.ScreenGui.Shop?

Edit: Could it be possible that you misspelt “Shop” while it’s actually lower-cased like “shop” by any chance?

1 Like

still doesnt work--------------

Are you sure you’re doing game.Players:GetPlayerFromCharacter(otherPart.Parent) and not game.Players:GetPlayerFromCharacter(otherPart.Parent.Name

my example code works just fine:

workspace.Part.Touched:Connect(function(hit)
	local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	
	if player then
		print("YES!")
	end
end)

The error states that ‘Shop’ is not a valid member of ScreenGui. I recommend you open your PlayerGui (while testing in studio) and see if thats the case?

1 Like

in wich part of the script do i need to replace it? I dont want to mess it up

Instead of doing ScreenGui.Shop, do ScreenGui:WaitForChild(“Shop”). This error might occur as the ‘Shop’ has not loaded in properly. Try changing all the ScreenGui.Shop to ScreenGui:WaitForChild(“Shop”).

This one, it should be obvious enough, but do not replace the code with just my un-modified example code, it won’t work, or well it will but it won’t open the gui unless you modify it to do so

image

Where do I make the change in the script (sorry if Im annoying with this, I really dont wanna mess this up)

I have literally told you that already. Find everything that says ScreenGui.Shop and change it to ScreenGui:WaitForChild(“Shop”)

done, still doesnt work, but there arent any errors though

Roblox studio have the same errors?

Or have other errors