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")
script.Parent.ProximityPrompt.Triggered:Connect(function()
event:FireServer();
end)
--This is the server script
print("Finding locals ss")
local Replicated = game:GetService("ReplicatedStorage");
local event = Instance.new("RemoteEvent", Replicated)
event.Name = "X"
print("Found Locals ss")
event.OnServerEvent:connect(function(player)
local allowed = player.Backpack.FindFirstChild("X")
if allowed then
print("Allowed")
else
print("Not allowed")
end
end)
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.
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.