Touch Part to disable the player's backpack

Hello DevForum! I am not a good scripter but I am trying to figure out how to make it so that when a player touches a part it disables their backpack. I tried to right my own code which might make me seem like a noob at scripting. And I understand that, but I just need some help getting this to work,

script.Parent.Touched:Connect(function(hit)
	local char = hit.Parent
	game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack,false)
end)
3 Likes

This line has to be done from the client.
Also, you should be using PlayerGui when working with Gui and stuff related to it.

Hi @Gear_Dev You’re code is not wrong,

But i guess it is a script server, so to disable the menu, player list or other player stuff you have to do it with a localscript.

So I suggest you once you get the char on the server to send an event to the client, and as soon as the client receives it, it disables the player’s backpack from the client.

That’s Wrong! PlayerGui cannot be used to disable emotes, playerlist or backpack You must necessarily call the StarterGui service.

The script is a local script inside of a part. So I am not quiet sure.

Oh Alr, LocalScript does not run on Workspace, so put it for example on PlayerScript and modify the Directory of part.

By PlayerScript do you mean StarterPlayer or StarterPlayerScripts (Sorry about this question I am just not sure what you are refering too.)

Im Talking About StarterPlayerScripts, sorry was thinking about player. (StarterPlayerScripts scripts go to PlayerScript when games run)

I have tested it and it did not work. Nothing showed up in the output. My backpack wasn’t disabled. I feel like I did something wrong because it isn’t connecting.

This is the current Local Script:

game.Workspace.OptionEnable1:Connect(function(hit)
	local char = hit.Parent
	game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack,false)
end)
1 Like

I can help you out.

  1. Make sure your local script is under StarterPlayer > StarterPlayerScripts
  2. Here’s an outlined fragment of code you can fill out
local StarterGui = game:GetService("StarterGui")

local player = game:GetService("Players").LocalPlayer
local part = game.Workspace.Part -- CHANGE THIS TO THE DIRECTORY OF THE PART
part.Touched:Connect(function(hit)
   if hit.Parent == player.Character then
      StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)
   end
end)

I hope this works and helps. If you have any questions feel free to comment under this :slight_smile:

2 Likes

Thank you so much this helped me a lot!

1 Like