I think the Hit.Character:MoveTo() isn’t working because of another teleporter or maybe because the position is out of reach ?
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)
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.
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)
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.
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
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
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