Character position issue

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
image

If you know how to help or fix the issue please let me know.

2 Likes

what is IDVerified? (Havn’t used studio in a month or so, idk what the icons look like now)

Nothing happens as in literally nothing? If so, add in print statements to see what the issue is

1 Like

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

Yes it is a tool. I only want the script to check if he has it, not holding it or activating it.

1 Like

Its a BillboardGUI. Really just ignore that

2 Likes

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.

Oh. Didn’t know that. So would this script work?

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)

I tried. Same issue, works once and then doesnt work

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.

ohhhhhhh. How about tihs then?

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)

Why is this here. It’s not even a property, it’s an event. It shouldn’t be used here.

sorry. so just plr.Character:FindFirstChild(“Access Card”)

???

Yes. that’s correct.

Also, try to use the CFrame of the character to set their location instead of Position.

It still happens. Heres a clip:

External Media

Have you tried debugging it? Like putting prints in parts of the code and seeing if it works.

No I will try that and report back.

So I put a print after the trigger event, after the id check, and after the teleportation. and it works once, and then it doesnt print any of them

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)
1 Like

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