it doesn’t work the way I want, it’s a video that shows the problem, I hope you understand
please just show the full video and not you character being resetted, try to share it with other websites or compress this cutting the parts of the video that isnt essential
try with a debounce:
local TeleportDebounce = true --this adds a debounce
local CurrentLocation = script.Parent
local Destination = game.Workspace.Teleport2
CurrentLocation.Touched:Connect(function(Touch)
local humanoid = Touch.Parent:FindFirstChildOfClass("Humanoid")
if humanoid and TeleportDebounce then -- this checks if the debounce is true, if not, it wont run
if Touch.Parent:FindFirstChild("HumanoidRootPart") then
TeleportDebounce = false -- set the variable to false, so that the code wont run until this become true
local startPosition = Destination.Position - Vector3.new(Destination.Size.X / 2, Destination.Size.Y / 2, Destination.Size.Z / 2)
local endPosition = Destination.Position + Vector3.new(Destination.Size.X / 2, Destination.Size.Y / 2, Destination.Size.Z / 2)
local position = Vector3.new(math.random(startPosition.X, endPosition.X), math.random(startPosition.Y, endPosition.Y), math.random(startPosition.Z, endPosition.Z))
Touch.Parent:FindFirstChild("HumanoidRootPart").Position = position
end
end
task.wait(5) --change this to whatever you like
TeleportDebounce = true -- this will return the debounce to true, so the code will run after x seconds
end)
the debounce is basically a boolean variable ( in this case ) to make sure the code wont run until the variable is set to true ( or false ), this is very used and maybe you heard of this.
I tried and it doesn’t work, I keep teleporting randomly, I want the teleportation to work only when I enter the portal
are you sure is the only script the part has for the teleport?
try to disable this script and check if it stills teleport
it is only one script that uses teleportation, so it has no way to collide with other teleports
try to disable the script after being teleported
I tried with enabled false and the problem persists, I don’t know how
enabled false for script, not for parts
search all scripts you have, and delete everything if necessary
there are currently 2 scripts in the game, that’s all, the second script is about texture
Have you tried using the MoveTo function instead of setting the humanoid’s position manually.
Touch.Parent:MoveTo(position)
have you tried to reset without teleporting?
yes, but the problem appear just i touched the portal
example??? for understand where is possible resolving
I copied your code into studio really quick, created some test parts and changed out this line:
Touch.Parent:FindFirstChild("HumanoidRootPart").Position = position
for this line:
Touch.Parent:MoveTo(position)
This seems to fix that issue for me.
thx a lot of help, this is the solution, but such a question, can this script collide with the future portals that will appear in the game?
Multiple parts having this script shouldn’t cause any issue I can think of.
I would suggest using tags and the CollectionService to implement this though.
Resource if you’ve never used tags:
CollectionService in a nutshell - Resources / Community Tutorials - Developer Forum | Roblox
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.