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.
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.
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.
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)
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.