Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I prevent someone teleporting to a certain area? [REPOST.]

Asked by 6 years ago

I'm trying to make a teleport script with some areas by which the user can't teleport to. However, at the moment, i'm struggling to get the mouse to detect the area by which is blocked from the user so the user ends up teleporting to it.

Debounce = false
local mouse = script.Parent.Parent:GetMouse()

game:GetService('UserInputService').InputBegan:connect(function(input, gameprossed)
if not gameprossed then

  if input.KeyCode == Enum.KeyCode.T and Debounce == false then
    if mouse.Hit.p == ("No").Position then
      print("No teleport")

    else

      Debounce = true

      local ReplicatedStorage = game:GetService("ReplicatedStorage")
      local Teleport = ReplicatedStorage:WaitForChild("Apparate")

      Teleport:FireServer(mouse.Hit.p)

      wait(2)
      Debounce = false
    end
  end
end
end)

There's no errors in output + no print in the output..

Any ideas on how to overcome it?

Please don't suggest a script which teleports players out of the location if they go in there as it will ruin the aspect of them not being able to enter in the first place.

Thank you.

0
What exactly is ("No").Position. And your issue might be that it doesn't know the No.position, or that when you click, it is just slightly above that position and doesn't count it. It should be a range, not a single position. Hope this helps. greenhamster1 180 — 6y
0
Yes sorry, I forgot to state that "No" was the part. However, I like your idea but i'm unsure but what you mean by using a range instead of a single position. If you could possibly show an example it may help me to understand on how to overcome this. :) xXTouchOfFrostXx 125 — 6y

1 answer

Log in to vote
1
Answered by
dionant 23
6 years ago
Edited 6 years ago

If I understand correctly, you teleport where you click.

If you want to not teleport to a part, try naming it to "No" and change your line 8.

This is your line 8. If the Position of the Part you clicked is equal to No's position, it doesn't teleport. What is "No"?

if mouse.Hit.p == ("No").Position then

This is my proposal. If the name of the part your mouse clicked is "No", then don't teleport.

if mouse.Hit.Name == "No" then

I hope I have helped!

EDIT: Since Hit.Name is not valid (Oops) this would be the proper line

if mouse.Target.Name == "No" then
0
I understand the idea of what you're trying to produce, however. Name isn't a valid member of CFrame so that wouldn't work. xXTouchOfFrostXx 125 — 6y
0
My bad. Why don't you try Mouse.Target? That's what I meant but confused Hit with Target. dionant 23 — 6y
0
It worked! Thank you! xXTouchOfFrostXx 125 — 6y
Ad

Answer this question