I’m trying to make it so a function stops, here’s the code
ProximityPrompt.Triggered:Connect(function()
if Debouce == false then
Debouce = true
ChatService:Chat(PartToDisplay,Settings.Message, Settings.ColorOfText)
ProximityPrompt.Enabled = false
talking() --the function
wait(Settings.DebouceTime)
-- line where I want to stop the function
ProximityPrompt.Enabled = true
Debouce = false
end
end)
the function’s purpose:
local function talking()
while true do
script.Parent.NotTalking.Transparency = 1
script.Parent.Talking.Transparency = 0
wait(.1)
script.Parent.NotTalking.Transparency = 0
script.Parent.Talking.Transparency = 1
wait(.1)
end
end
can anyone help? im about to go to sleep because its 10 PM where I live.
hopefully people respond when I wake up, please do!
Loops stop the code, you must use task.spawn to avoid this
local PartToDisplay = script.Parent
local ProximityPrompt = script.Parent.ProximityPrompt
local ChatService = game:GetService("Chat")
local Debouce = false
local Settings = {
DebouceTime = 5,
Message = "hello, i am rock.",
ColorOfText = Enum.ChatColor.White
}
local function talking()
local cancel = false
task.spawn(function()
while not cancel do
script.Parent.NotTalking.Transparency = 1
script.Parent.Talking.Transparency = 0
task.wait(0.1)
script.Parent.NotTalking.Transparency = 0
script.Parent.Talking.Transparency = 1
task.wait(0.1)
end
end)
return function()
cancel = true
end
end
ProximityPrompt.Triggered:Connect(function()
if Debouce == false then
Debouce = true
ChatService:Chat(PartToDisplay,Settings.Message, Settings.ColorOfText)
ProximityPrompt.Enabled = false
local F = talking()
task.wait(Settings.DebouceTime)
F()
ProximityPrompt.Enabled = true
Debouce = false
end
end)