I want to make it so that the backpack is disabled when I’m in the safezone but that is not working I’ve tried using PlayerGui:SetCoreGuiEnabled
local SafeZoneArea = game.Workspace.SafeZone
local Players = game:GetService("Players")
function CheckIfPlayerIsInArea(character)
local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")
if humanoidRootPart then
return humanoidRootPart:IsDescendantOf(SafeZoneArea)
end
return false
end
Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
while not character:FindFirstChild("HumanoidRootPart") do
character:WaitForChild("HumanoidRootPart")
end
local function updateBackpack()
local inSafeZone = CheckIfPlayerIsInArea(character)
local playerGui = player:WaitForChild("PlayerGui")
playerGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, not inSafeZone)
end
updateBackpack()
local connection = character.HumanoidRootPart.Touched:Connect(updateBackpack)
character.AncestryChanged:Connect(function(_, parent)
if parent == nil then
connection:Disconnect()
end
end)
end)
end)
module script in replicated storage (make module name as “BackpackUI”)
local m = {}
function m:CheckIfPlayerIsInArea(plr)
local humanoidRootPart = plr.Character:FindFirstChild("HumanoidRootPart")
if humanoidRootPart then
return humanoidRootPart:IsDescendantOf(SafeZoneArea)
end
return false
end)
function m:updateBackpack(plr)
local inSafeZone = CheckIfPlayerIsInArea(plr)
local playerGui = plr:WaitForChild("PlayerGui")
playerGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, not inSafeZone)
end)
return m
local script in starter player script
local m = require(game:GetService("ReplicatedStorage").BackpackUI)
local RS = game:GetService("RunService")
local plr = game:GetService("Players").LocalPlayer
RS:Heartbeat:Connect(function()
m:updateBackpack(plr)
end)
( this might have few errors because it is written by mobile )