Help with gui appearing when it shouldnt

Hello, this script should make it so a gui appears when i touch a block, it used to work but after some editing without testing it stopped, Now it appears when i spawn in. I checked output and no errors showed. Please help me fix it.

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 ReplicatedStorage = game:GetService('ReplicatedStorage')
local remoteEvent = ReplicatedStorage:WaitForChild('BuyTool')

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

local function buyTool1()
	remoteEvent:FireServer()
end

open.Touched:Connect(shopMenu)
closeButton.MouseButton1Click:Connect(closeMenu)
buy_1.MouseButton1Click:Connect(buyTool1)
--buy_2.MouseButton1Click:Connect()
--buy_3.MouseButton1Click:Connect()
1 Like

You are doing Shop.Visible = false and frame.Visible = false.

Maybe this is the problem.

1 Like

after trouble shooting i found that this is the error, i dont know how to fix it, can you help?

local remoteEvent = ReplicatedStorage:WaitForChild('BuyTool') ,

the lua cut off some of my message, i tried to send this:
local ReplicatedStorage = game:GetService(‘ReplicatedStorage’)
local remoteEvent = ReplicatedStorage:WaitForChild(‘BuyTool’)

Is the RemoteEvent in ReplicatedStorage called “BuyTool”? That may be the error, if it says Infinite Yield possible on ReplicatedStorage.BuyTool

1 Like

You’re a life saver, i would have never noticed this, thank you.

1 Like

You’re welcome! :grinning: Have fun!

2 Likes