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!
--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)
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?
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?
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