ProximityPrompt.Triggered and Hit.Character:MoveTo() BUG

I think the Hit.Character:MoveTo() isn’t working because of another teleporter or maybe because the position is out of reach :confused:?
I couldn’t find this issue elsewhere.

Script:

local Part = script.Parent
local Active = true

Part.ProximityPrompt.Triggered:Connect(function(Hit)
	if Active then
		wait()
		Active = false
		print(Active)
		local RNG = math.random(1,4)
		Hit.Character:MoveTo(workspace.Spawn["SpawnLocation" .. RNG].Position + Vector3.new(0, 4, 0))
		Hit.leaderstats.Wins.Value = Hit.leaderstats.Wins.Value + 1
		wait()
		Active = true
	end
end)
4 Likes

The issue might be related to how you’re using math.random and workspace.Spawn. Here are a few suggestions:

Make sure that there are SpawnLocation objects in your workspace with names like “SpawnLocation1”, “SpawnLocation2”, etc. Instead of accessing workspace.Spawn directly, consider using workspace:WaitForChild(“Spawn”) to ensure that the “Spawn” object is present in the workspace. Ensure that Hit.Character has a leaderstats property. If not, you may encounter an error. You can check for this by using if Hit.Character:FindFirstChild(“leaderstats”) then before attempting to access Hit.leaderstats.Wins.

2 Likes

When I use “Play Here” everything works fine, But when I spawn normally it doesn’t work

Spawn Position 20, 0.5, -20
Part Position 3545, 1, -0

3 Likes

I tested everything and it works fine, are you sure all the spawns are anchored?

2 Likes

It looks like you have your debounce switched and an extra wait, it should be:

local Part = script.Parent
local Active = false

Part.ProximityPrompt.Triggered:Connect(function(Hit)
	if not Active then
		Active = true
		print(Active)
		local RNG = math.random(1,4)
		Hit.Character:MoveTo(workspace.Spawn["SpawnLocation" .. RNG].Position + Vector3.new(0, 4, 0))
		Hit.leaderstats.Wins.Value = Hit.leaderstats.Wins.Value + 1
		wait()
		Active = false
	end
end)

Edit: @1ocaluser here’s a slightly more cleaned-up version if you want to use it:

local Part = script.Parent
local Active = false

Part.ProximityPrompt.Triggered:Connect(function(Hit)
	if Active then return end
	Active = true
	print(Active)

	local RNG = math.random(4) -- If the minimum value is 1, you can simply write the maximum value and it will still work without error
	Hit.Character:MoveTo(workspace.Spawn["SpawnLocation"..RNG].Position + Vector3.new(0, 4, 0))
	Hit.leaderstats.Wins.Value += 1

	task.wait() -- It's better to use task.wait instead of wait
	Active = false
end)
1 Like

The issue is your part is too far out of the map it’s self, therefore it gets removed when you start the game.

1 Like

I’ve moved everything, it’s in workspace now and it’s still happening. This doesn’t happen when I use .Touched

1 Like

The same issue still occurs. Somehow the issue is gone if I use .Touched. I tested it again using proximity promt in a different place and somehow the issue doesn’t occur.

1 Like

Is the RequiresLineOfSight property of the ProximityPrompt set to true? If yes, then setting it to false might solve your problem

1 Like

It’s already enabled, I haven’t done any changes to the properties

2 Likes

Try setting it to false, there might be something obstructing it in the part you want to use that’s preventing the prompt from working correctly

Edit: @1ocaluser also as a test make sure that the value of Active is being printed in the output because if it is then the problem might not be happening because of the prompt

It’s not printing true or false

That means something is preventing the prompt from working correctly

If possible, could you show me a screenshot of the prompt and its parents in the Explorer please?

Also, a screenshot of the prompt’s settings would be very helpful as well

image

I removed the debounce and replaced it with if true, same issue is still happening

Does the prompt show up when your character is near the part or does it flicker (turns visible and invisible repeatedly)

I see that RequiresLineOfSight is still set to true so make sure it’s set to false like this:

PromptExample

The blue checkmark should disappear when it’s false

1 Like

Turns out the :Connect isn’t getting reached

1 Like

That’s odd because nothing in your script could cause that unless it isn’t the full script

I also suggest you could replace the prompt with a ClickDetector and try:

local Part = script.Parent
local Active = false

Part.ClickDetector.MouseClick:Connect(function(Hit)
	if Active then return end
	Active = true
	print(Active)

	local RNG = math.random(4) -- If the minimum value is 1, you can simply write the maximum value and it will still work without error
	Hit.Character:MoveTo(workspace.Spawn["SpawnLocation"..RNG].Position + Vector3.new(0, 4, 0))
	Hit.leaderstats.Wins.Value += 1

	task.wait() -- It's better to use task.wait instead of wait
	Active = false
end)

although you’ll always need to click the part to run the function since ClickDetectors don’t read keyboard input

It’s working with the click detector

1 Like

Prompts seem to cause issues for a lot of users/players so if you don’t mind using ClickDetectors I suggest using them instead, ClickDetectors seem to be more reliable and consistent :slightly_smiling_face::+1:

1 Like