Hey, so I have a part then when you touch it should pull up a gui screen, while it’s up for a few seconds you teleport. Once you teleport it comes off the screen. I have it working where when you touch the part the gui pops up, but the bug is that the gui gets stuck on my screen and it does not teleport me.


4 Likes
Does it come out as an error or something?
As @PuffoThePufferfish said, you should use the debounce function so the Touched event doesn’t mess with the teleportation and GUI thingy until the function has finished running.
3 Likes
You need to implement a debounce in the function, since the .Touched event often-times fires multiple times.
example (using a nested comparison):
local canTouch = true
part.Touched:Connect(function()
if canTouch then
canTouch = false
-- code here
task.wait(1.0)
canTouch = true
end
end)
Additionally, you could utilize TweenService to better your code (so you don’t need the transparency loops)
1 Like
Hello, I am here to help you, here is the solution, any error, let me know and then I will explain.
------------/ Locations /------------
local LocalPlayer = game:GetService('Players').LocalPlayer
local TeleportPart = workspace.Teleport1
local Teleporting = false -- Debounce
------------/ Method /------------
TeleportPart.Touched:Connect(function(Hit)
if Teleporting == false then
if Hit.Parent:FindFirstChild('Humanoid') and Hit.Parent:FindFirstChild('Humanoid').Health ~= 0 and Hit.Parent == LocalPlayer.Character then
script.Parent.FadeFrame.Visible = true
Teleporting = true
for i = 1, 20 do
script.Parent.FadeFrame.BackgroundTransparency -= 0.1
task.wait()
end
game.Players.LocalPlayer.Character:WaitForChild('HumanoidRootPart').CFrame = workspace.TeleportLocation.CFrame * CFrame.new(0, 15, 0)
for i = 1, 20 do
script.Parent.FadeFrame.BackgroundTransparency += 0.1
task.wait()
end
Teleporting = false
end
end
end)
The variable IsPlaying serves as a debounce so that the function is not repeated multiple times while the player is being teleported.
Task waiting is to wait a while.
Try this. If you have any questions, let me know, have a good night.
1 Like
When I place this in the script, there is a warning for the part.Touched:Connect(function(). The “part” is underlined.
1 Like
There are no Erros in the script analysis and it still does the same thing.
1 Like
You can just create a new variable called debounce and put it outside the function.
Then inside the part.Touched function, make a new if-statement that checks if debounce is false (or true if you like being inverted). Inside the if-statement is where you normally put the teleporting and GUI stuff. But first make a new line that sets the debounce to true and make a line at last before the end of the if-statement where you set the debounce to false.
Like this:
local debounce = false
Part.Touched:Connect(function(hit)
if not debounce then
debounce = true
-- The code where you do the teleportation thing and gui stuff. just copy line 5-16 from the image to here
debounce = false
end
end)
1 Like
I have no idea on how to do that lol
1 Like
I was watching a youtube video on this and I did exactly what the guy did, but his works and mine kinda works.
1 Like
Alright, also you forgot the player and part variables from Line 1-2 in the first image. Make sure to include that.
1 Like
You need to put those 2 lines outside the function.
1 Like
That’s because the Part in Line 6 has a capital letter.
Variables are case-sensitive.
Like if you create a variable named “PaRt”. You need to type that specific identifier with cases and not “part” to access this variable.
You can either make all that lowercase, like “part” or change the variable name in line 4. I recommend you just make “Part” in Line 6 lowercase.
1 Like
Well now the script just does not work at all.
1 Like
How so? Did you put the script in a different location or something?
1 Like
My original script worked on bringing the gui up but failed to teleport and remove the gui after a few seconds.
1 Like
No I did not. It is in the same place it was before.
To answer the question “Like did it show any errors or something?” the answer is no
1 Like
Like did it show any errors or something?
1 Like