Script Support needed

Hello, I am trying to make a system so when you step on a part some GUI’s get visible. I am setting them to be enabled when you step on a part but it doesn’t work? Can anybody help? I can’t find anything when searching for it.

local Cam1 = game.Workspace.ShopCameras.Camera1
local Cam2 = game.Workspace.ShopCameras.Camera2
local Cam3 = game.Workspace.ShopCameras.Camera3
local Shop = game.Workspace.Shop
local cam = workspace.CurrentCamera
local player = game.Players.LocalPlayer
local LeftArrow = game.StarterGui.ShopGUI.LeftArrow
local RightArrow = game.StarterGui.ShopGUI.RightArrow
local PurchaseButton = game.StarterGui.ShopGUI.PurchaseButton
local ExitButton = game.StarterGui.ShopGUI.ExitButton

Shop.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		cam.CameraType = "Fixed"
		cam.Focus = workspace.FocusParts.FocusPart1.CFrame
		cam.CFrame = Cam1.CFrame
		cam.FieldOfView = 40
		game.StarterGui.ShopGUI.Enabled = true
	end
end)
2 Likes

Make sure they are Visible too

StarterGui is cloned to the player when they join the game, you have to use player.PlayerGui to get the gui instead.

2 Likes

I’m guessing this is a server script. Try this out instead:

local PS = game:GetService("Players")

local Cam1 = game.Workspace.ShopCameras.Camera1
local Cam2 = game.Workspace.ShopCameras.Camera2
local Cam3 = game.Workspace.ShopCameras.Camera3
local Shop = game.Workspace.Shop
local cam = workspace.CurrentCamera
local player = game.Players.LocalPlayer
local LeftArrow = game.StarterGui.ShopGUI.LeftArrow
local RightArrow = game.StarterGui.ShopGUI.RightArrow
local PurchaseButton = game.StarterGui.ShopGUI.PurchaseButton
local ExitButton = game.StarterGui.ShopGUI.ExitButton

Shop.Touched:Connect(function(hit: BasePart)
	local char = hit:FindFirstAncestorWhichIsA("Model")
	local player = char and PS:GetPlayerFromCharacter(char)
	
	if player then
		cam.CameraType = "Fixed"
		cam.Focus = workspace.FocusParts.FocusPart1.CFrame
		cam.CFrame = Cam1.CFrame
		cam.FieldOfView = 40
		player.PlayerGui.ShopGUI.Enabled = true
	end
end)
1 Like

A few notes:

1.Instead of cam.CameraType == "Fixed", do: cam.CameraType = Enum.CameraType.Fixed [more accurate and has less chances of having issues].

2.You can’t directly access guis like this from StarterGui, you should use PlayerGui instead.

2 Likes