Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

trying to make a proximity prompt teleport door that requires a key?

Ok I'm new to scripting and I can't figure out how to make it where it checks for the key(or my tool) BUT when its equipped. I have it working for when its in my backpack it teleports me but I cant equipped the key when I want to tp

sorry if it looks like stupid code I'm just new

line 26 is where I try to make it for when the key is equipped it teleports me when I click on e on the door


player = game:GetService("Players")
local Tp = workspace.Backrooms
local Target = "Key"
local Proximity = script.Parent
local Door = script.Parent.Parent.Parent.Door


script.Parent.Triggered:Connect(function(player)
	local Backpack = player:WaitForChild("Backpack")
	if Backpack:FindFirstChild("Key") then
		local Key = Backpack:FindFirstChild("Key")
		
		
			
			game.ReplicatedStorage.GuiAnimate2:FireClient(player)
			wait(5)
			player.Character.HumanoidRootPart.CFrame = CFrame.new(Tp.Position)
		else
			
			print("No Working Or Doesn't have key")
		end
end)


game.Players.PlayerAdded:Connect(function(plr)
script.Parent.Triggered:Connect(function(player)
	local IsInBackpack = false
		local Key = player.Backpack:FindFirstChild()
		if Key or Key.Equipped then
			IsInBackpack = true
			game.ReplicatedStorage.GuiAnimate2:FireClient(player)
			wait(5)
			player.Character.HumanoidRootPart.CFrame = CFrame.new(Tp.Position)
		end
	end)
	end)








2 answers

✓ Accepted answer

Here ya go!

Insert a Script inside of the ProximityPrompt (not a module script nor a localscript)

Let's use a Triggered event on the ProximityPrompt that is to let code happen when the ProximityPrompt is activated, Then we check if we find something called Key in the Backpack or character, The reason why we look in the Character is when the player equips the key, It goes inside their Character, Otherwise when it's unequipped it goes inside of the Player's Backpack, Then we use :Destroy() in order to remove the door from the game and we print Door opened to print to the server that the Door has opened!

script.Parent.Triggered:Connect(function(player)
	if player.Backpack:FindFirstChild("Key") or player.Character:FindFirstChild("Key") then
		
		script.Parent.Parent:Destroy()
		print("Door opened")
		
	end
end)

1 comment

1

Thanks that worked

If I am correct, once you equip something, it is taken out of the backpack and into the character. Some info from htis tells us that, Equipping a tool moves it from the Backpack and into a player’s Character|character model in the Workspace. So theoretically you would use

player.Character.Key

instead of looking in the back pack for tools.

This discussion is preserved as it was. New answers, comments, and votes are closed.