Send a event based on item in inventory

I’m trying to make a script where it detects what item you have in your inventory and based on that it will open a door or send a event.

--This is the local script
print("locals found ls")
local ReplicatedService = game:GetService("ReplicatedStorage");
local plyr = game:GetService("Players").LocalPlayer
local event = ReplicatedService:WaitForChild("X");
print("locals Found ls")

--This is the server script
print("Finding locals ss")
local Replicated = game:GetService("ReplicatedStorage");
local event ="RemoteEvent", Replicated)
event.Name = "X"
print("Found Locals ss")

	local allowed = player.Backpack.FindFirstChild("X")
	if allowed then
		print("Not allowed")

This is also how I have the local script ordered.

1 Like

In this part of your script, a colon must be used before FindFirstChild, not a period.

local allowed = player.Backpack:FindFirstChild("X")

Hope this helps!

Also, if you will be trying to use a proximity prompt for your game, please do note that it’s in beta phase and will only be available in Studio, unless Roblox makes it live.

1 Like

ProximityPrompt CANNOT be in a local script. It MUST be in a server script parented to a part.

1 Like

You can listen a proximity prompt’s triggered event through local scripts as stated in Proximity Prompt Studio Beta:

1 Like

I tried replicating your problem and it seems that Local scripts will not run when they are parented to the workspace.

I recommend placing the local script under StarterPlayerScripts which is parented to the StarterPlayer folder. Then, change the reference for the Proximity Prompt (workspace.Part.ProximityPrompt). Don’t forget to place a colon, instead of a period, before FindFirstChild.

1 Like