Hello. I’ve made a script that whenever you trigger a prompt it checks if you have a specific item in your inventory and if you do it teleports you. Here is the issue, you can only do it once for some reason. Whenever I go back and trigger the prompt again nothing happens.
Here is my code:
local verified = script.Parent.Parent.IDVerified
local prompt = script.Parent
prompt.Triggered:Connect(function(plr)
if plr.Backpack:FindFirstChild("Access Card") then
plr.Character.HumanoidRootPart.Position = workspace.GateTeleportTo.Position
end
end)
And here is my workspace of the prompt
If you know how to help or fix the issue please let me know.
is “Access Card” a tool?, if so, you should check both the player character and backpack, since when they equip the tool goes to the player character.
and you are only checking the backpack
If you ignore the possibility of the tool being in the player’s hands, then the script won’t work if the player is holding the tool. Remember, whenever the player holds a tool, it disappears from the Backpack. Even though you have the tool, if you just check the backpack and the player is holding the tool, it won’t detect it.
local verified = script.Parent.Parent.IDVerified
local prompt = script.Parent
prompt.Triggered:Connect(function(plr)
if plr.Backpack:FindFirstChild("Access Card") or plr.Backpack["Access Card"].Equipped then
plr.Character.HumanoidRootPart.Position = workspace.GateTeleportTo.Position
end
end)
Let me reiterate. It disappears (is gone) from the Backpack (you can’t access it from it). It is reparented from the Backpack to the Character. This means you have to check the character for the tool instead.
local verified = script.Parent.Parent.IDVerified
local prompt = script.Parent
prompt.Triggered:Connect(function(plr)
if plr.Backpack:FindFirstChild("Access Card") or plr.Character:FindFirstChild("Access Card") .Equipped then
plr.Character.HumanoidRootPart.Position = workspace.GateTeleportTo.Position
end
end)
I figured it out. Thanks.
I just deleted the old code and tried making a new code and that seems to work close enough to what I how I want to work.
Script:
local verified = script.Parent.Parent.IDVerified
local prompt = script.Parent
prompt.Triggered:Connect(function(plr)
if plr.Character:FindFirstChild("Access Card") then
verified.TextLabel.Text = "ID Checks out. Teleporting..."
wait(2)
plr.Character.HumanoidRootPart.CFrame = workspace.GateTeleportTo.CFrame
verified.TextLabel.Text = "Click on the Proximity Prompt"
else
verified.TextLabel.Text = "ID Must be equipped if you own it!"
wait(3)
verified.TextLabel.Text = "Click on the Proximity Prompt"
end
end)