Teleporting Script not working!

What do you want to achieve?
A way to stop anyone from teleporting while CanCollide is turned off

I’ve tried making a system that checks if the player is touching it while CanCollide is turned off

Here it is:

if game.Workspace.NoAnime.Touched while 
game.Workspace.NoAnime.CanCollide == false then
h.parent.HumanoidRootPart.CFrame = CFrame.new(workspace["NoAnime"].Position)
end

This however, turned up with several errors. No clue where to go from here. Please help me!

Also, here’s the script above it:

script.Parent.Touched:Connect(function(h)
local hum = h.Parent:FindFirstChild("Humanoid")
if hum ~= nil then
	h.parent.HumanoidRootPart.CFrame = CFrame.new(workspace["NoAnime2"].Position)
end
end)
2 Likes

you can’t do a if while then
that doesn’t even make sense
it’s either if then or while do

How would I rework the script to work with just if, then?

local TouchedIt = false

game.Workspace.NoAnime.Touched:Connect(function()
    TouchedIt = true
end)

game.Workspace.NoAnime.TouchEnded:Connect(function()
    TouchedIt = false
end)

while TouchedIt  == true and game.Workspace.NoAnime.CanCollide == false do
   h.parent.HumanoidRootPart.CFrame = CFrame.new(workspace["NoAnime"].Position)
end

Something like this I Guess

Tried this, doesn’t have any errors, but doesn’t work. h seems to show up underlined in red.

local TouchedIt = false
local h

game.Workspace.NoAnime.Touched:Connect(function(part)
TouchedIt = true
h = part
end)

game.Workspace.NoAnime.TouchEnded:Connect(function()
TouchedIt = false
end)

while TouchedIt == true and game.Workspace.NoAnime.CanCollide == false do
h.parent.HumanoidRootPart.CFrame = CFrame.new(workspace[“NoAnime”].Position)
end

Maybe this would work? I’m on mobile sorry for messy answer. The bold code was the lines that I added that could work

There is a touch property that can be turned on and off in nearly every physical part’s properties. This mean that no .Touched events can occur from that part while that property is disabled.

Didn’t work :frowning:, so many people have tried at this point and nobody can fix it.

What are you refering to in the code? Or were you trying to reply to someone?

I’m replying to you.
If you don’t want a part to send touch events then disable the “CanTouch” property in a part.

Hi, I will be answering your question. Try this script.

script.Parent.Touched:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
local char = workspace[player.Name]
local waittime = 5 -- insert a time that will be used to change the debounce
local debounce = false
local parttoteleportto = game.Workspace.TestPart -- insert the part that you want the player to teleport to.
local success,err = pcall(function()
if debounce == false then
char:MoveTo(parttoteleportto.Position)
end
end)
if successs then
debounce = true
wait(timetowait)
debounce = false
end
end)

I hope this helped you, let me know! :relaxed:

I went to sleep. Anyways, this didn’t work. It stopped me from teleporting but when collisions were turned on from another script, I wasn’t able to teleport.

Is there a fix to my issue? (Charrrr)

Is there a reason why you don’t just disable touch events for that period of time?

Otherwise, an if then statement checking whether the part has collision or not can also work.