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,

	local char = hit.Parent

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:

	local char = hit.Parent
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
   if hit.Parent == player.Character then
      StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)

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


Thank you so much this helped me a lot!

1 Like