Hello! How can I make a delay to clicking the button this script is located too? Such as its on a TextButton. How can I make it so they have a 5 second delay to clicking it, so they can not spam it. How can I do this? This script is my Teleporting script by the way.
here is the code:
-- Functions
local player = game:GetService("Players").LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")
local Player = game.Players.LocalPlayer
local Character = Player.Character
-- Disable walking Functions
local players = game:GetService("Players")
local player = players.LocalPlayer or players.PlayerAdded:wait()
local character = player.Character or player.CharacterAdded:wait()
local humanoid = character:WaitForChild("Humanoid")
-- when you click the button
script.Parent.MouseButton1Click:Connect(function()
script.Disabled = false
-- See if you own the door
if Player.Doors[script.Parent.Name].Value == true then
Character.HumanoidRootPart.CFrame = game.Workspace.DoorsKeys[script.Parent.Name].CFrame
local debounce = false
if debounce == false then
debounce = true
-- disable the walkspeed
do
humanoid.WalkSpeed = 0
humanoid.JumpPower = 0
end
-- Opens the Loading World frame
game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.All, false)
playerGui.LoadingWorld.Frame.Visible = true
-- Change Text to Loading...
playerGui.LoadingWorld.Frame.TextLabel.Text = "Teleporting to Snowy Fields"
wait(0.5)
playerGui.LoadingWorld.Frame.TextLabel.Text = "Teleporting to Snowy Fields."
wait(0.5)
playerGui.LoadingWorld.Frame.TextLabel.Text = "Teleporting to Snowy Fields.."
wait(0.5)
playerGui.LoadingWorld.Frame.TextLabel.Text = "Teleporting to Snowy Fields..."
wait(0.1)
-- The Position when it's done
playerGui.LoadingWorld.Frame:TweenPosition(UDim2.new(1, 0, 0, 0),"InOut","Sine",1, false, function()
playerGui.LoadingWorld.Frame.Visible = false
playerGui.LoadingWorld.Frame.Position = UDim2.new(0, 0, 0, 0)
game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.All, true)
end)
wait(1)
-- reenable walk speed
do
humanoid.WalkSpeed = 16
humanoid.JumpPower = 50
end
task.wait(1)
debounce = false
end
-- If you do not own the location
else
script.Parent.TextLabel.Text = "You do not own this Location"
wait(0.85)
script.Parent.TextLabel.Text = "Snowy Fields"
end
-- disables the script
wait(0.2)
script.Disabled = false
end)
-- Functions
local player = game:GetService("Players").LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")
local Player = game.Players.LocalPlayer
local Character = Player.Character
-- Disable walking Functions
local players = game:GetService("Players")
local player = players.LocalPlayer or players.PlayerAdded:wait()
local character = player.Character or player.CharacterAdded:wait()
local humanoid = character:WaitForChild("Humanoid")
-- Delay Click Function
local db = false
-- when you click the button
script.Parent.MouseButton1Click:Connect(function()
if db == false then
db = true
script.Disabled = false
-- See if you own the door
if Player.Doors[script.Parent.Name].Value == true then
Character.HumanoidRootPart.CFrame = game.Workspace.DoorsKeys[script.Parent.Name].CFrame
local debounce = false
if debounce == false then
debounce = true
-- disable the walkspeed
do
humanoid.WalkSpeed = 0
humanoid.JumpPower = 0
end
-- Opens the Loading World frame
game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.All, false)
playerGui.LoadingWorld.Frame.Visible = true
-- Change Text to Loading...
playerGui.LoadingWorld.Frame.TextLabel.Text = "Teleporting to Snowy Fields"
wait(0.5)
playerGui.LoadingWorld.Frame.TextLabel.Text = "Teleporting to Snowy Fields."
wait(0.5)
playerGui.LoadingWorld.Frame.TextLabel.Text = "Teleporting to Snowy Fields.."
wait(0.5)
playerGui.LoadingWorld.Frame.TextLabel.Text = "Teleporting to Snowy Fields..."
wait(0.1)
-- The Position when it's done
playerGui.LoadingWorld.Frame:TweenPosition(UDim2.new(1, 0, 0, 0),"InOut","Sine",1, false, function()
playerGui.LoadingWorld.Frame.Visible = false
playerGui.LoadingWorld.Frame.Position = UDim2.new(0, 0, 0, 0)
game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.All, true)
end)
wait(1)
-- reenable walk speed
do
humanoid.WalkSpeed = 16
humanoid.JumpPower = 50
end
task.wait(1)
debounce = false
end
-- If you do not own the location
else
script.Parent.TextLabel.Text = "You do not own this Location"
wait(0.85)
script.Parent.TextLabel.Text = "Snowy Fields"
end
--
wait(0.2)
script.Disabled = false
--
wait(1)
db = false
end
end)
I saw pretty much this same script on another devforum post, but it seemed to not work, but this worked! I really do appreciate it!