Problem with getting players backpack

Hey, so i feel really stupid however for some reason i am unable to get the players backpack to check for a tool. If the player has this tool then they will be able to open the door. If not then they can’t open the door.

Code:

local ProximityPromptService = game:GetService("ProximityPromptService")
local TweenService = game:GetService("TweenService")

function PromptTriggered(Prompt)
	if Prompt.Name == "DoorPrompt" then
		Prompt.Enabled = false
		
		local Door = Prompt.Parent.Parent.DoorModel.PrimaryPart
		
		local Tween = TweenService:Create(Door, TweenInfo.new(2), {CFrame = Door.CFrame * CFrame.new(Door.Size.Y * 0, 10, 0)})
		Tween:Play()
		
		local function TweenCompleted()
			task.wait(4)
			
			local ClosingTween = TweenService:Create(Door, TweenInfo.new(2), {CFrame = Door.CFrame * CFrame.new(Door.Size.Y * 0, -10, 0)})
			ClosingTween:Play()
			
			local function ClosingTweenCompleted()
				Prompt.Enabled = true
			end
			
			ClosingTween.Completed:Connect(ClosingTweenCompleted)
		end
		
			Tween.Completed:Connect(TweenCompleted)
			
  end
end
	ProximityPromptService.PromptTriggered:Connect(PromptTriggered)

Everything works as intended, I just want to make it so you need the tool “Keycard” for the player to actually be able to open the door.

So if you look at the documentation for ProximityPrompt.Triggered:

You’ll see that it returns the player who triggered the prompt. From there, you can just do something like:

proximityPrompt.Triggered:Connect(function(player) 	if player.Backpack:FindFirstChild('Keycard Name') then 		OpenDoor() 	end end)

I’m not sure why, but I’m unable to paste the code with the proper indents for some reason…

1 Like

Thanks for the fast reply, however i try to implement this but it does not appear to work. How should i implement it within my script? I keep getting errors with my current "end"s

Yes, I can’t paste the script properly anymore due to Roblox’s update that just released.
It comes up looking like this:

image

Had to manually add the proper spacing:

proximityPrompt.Triggered:Connect(function(player) 
	if player.Backpack:FindFirstChild('Keycard Name') then
		-- code to open door
	end
 end)


This is what it currently looks like when i do that.

You can get rid of your previous function. You kind of stuffed it inside of the one I wrote.

That function connected most of my things. (Sorry if i’m being stupid haha im a bit sleepy)

Ah, sorry. I see what you were doing. Then you can also use PromptTriggered:

image

ProxomityPromptService.PromptTriggered:Connect(function(prompt,player) 
	if prompt.Name == 'DoorPrompt' and player.Backpack:FindFirstChild('Keycard Name') then
		-- code to open door
	end
 end)

You’ll of course have to appropriately assign the variables.

I still appear to be getting an error at the bottom
image

Ignore the top one. That is due to a spelling error lol

You can remove the bottom 2 lines as you’re no longer using them.

1 Like

try your current code but here

make it function PromptTriggered(Prompt,Player) as PromptTriggered returns both the prompt and player

Thanks this worked :slight_smile: i really appreciate it

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.