Need help with a dialogue cooldown and distance activation

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want to add a cool down to the dialogue activation in my game
  2. What is the issue?
    My dialogue can be repetitively used if you are standing on the brick, I need help converting the gui from enabling from standing on the block into being a certain distance away from the part, and have it disable if it is farther then that. I am also trying to make it so that the dialogue can not be activated for 15 seconds after use.
  3. What solutions have you tried so far?
    I tried to look for solutions on the developer hub and on youtube, I can not find anything to help.

Screenshots of Explorer:
Screen Shot 2020-05-08 at 7.33.44 PM
(The part used to enable the GUI.)
Screen Shot 2020-05-08 at 7.29.56 PM
(The Dialogue UI being enabled from the part.
Screen Shot 2020-05-08 at 7.29.27 PM

The Current Script being used for the part:

script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid")then
game.ReplicatedStorage.Popup:FireClient(game.Players:GetPlayerFromCharacter(hit.Parent))

end
end)

The current script being used for the dialogue:
if game.StarterGui.UncleDialogue.ImageLabel.Visible == true and game.StarterGui.UncleDialogue.TextLabel.Visible == true then

local text = "Hehehe, I'm Uncle Steve."

local text2 = "Now go away so I can gamble."

local text3 = "I said go away."

local text4 = "If you are gonna just stay there,"

local text5 = "then atleast join The Uncles group."

for i = 1, #text do

script.Parent.TextLabel.Text = string.sub(text, 1, i)

wait()

end

wait(5)

for i = 1, #text2 do

script.Parent.TextLabel.Text = string.sub(text2, 1, i)

wait()

end

wait(2.2)

for i = 1, #text3 do

script.Parent.TextLabel.Text = string.sub(text3, 1, i)

wait()

end

wait(2.2)

for i = 1, #text4 do

script.Parent.TextLabel.Text = string.sub(text4, 1, i)

wait()

end

wait(0.6)

for i = 1, #text5 do

script.Parent.TextLabel.Text = string.sub(text5, 1, i)

wait()

end

wait(1.5)

game.Players.LocalPlayer.PlayerGui.UncleDialogue.Enabled = false

end

If anyone can help please reply in the comments.

You can use magnitude to detect a dist from an object to another so you can use it to check if the player’s humanoidrootpart is close to the part. Then to cool down you can add a debounce.

Denounce is always your friend on cooldowns

local Debounce = false
local Children = 1 -- edit this on what you want
script.Parent.Touched:Connect(function(hit)
if Debounce == false then
Debounce = true
if hit.Parent:FindFirstChild("Humanoid")then
game.ReplicatedStorage.Popup:FireClient(game.Players:GetPlayerFromCharacter(hit.Parent))

end
wait(Cooldown)
Debounce = false
end)

You should use a debounce for this, and for the next you should use magnitude, have a good day and good luck. :slight_smile:

Hey you can use debounce for cooldown

local debounce = false

if not debounce then
debounce = true
wait(1)
debounce = false
end)

And for the other one you should try out magnitude.

local magnitude = (workspace.Part1.Position - workspace.Part2.Position).Magnitude
print(magnitude)