So i made a thing that when you click an NPC, some text appears on screen so he talks to you, and he gives u a tool to complete the task he gives you. But i want to add a cooldown to this so if player clicks the NPC while the NPC is talking it will get bugged, i dont want this to happen. And also i dont want it to give the tool anymore if a player already clicked the NPC and got the tool.
Here is scripts bc its so hard to explain like that:
First this is the script i used in the NPC;
script.Parent.ClickDetector.MouseClick:Connect(function(plr)
game.ReplicatedStorage.guiEventA:FireClient(plr)
wait(27)
game.ReplicatedStorage.Bottle:Clone().Parent = plr.Backpack
end)
And then the local script in StarterGui;
local textlabel = script.Parent:WaitForChild("TextLabel")
local player = game.Players.LocalPlayer
local char = player.Character
game.ReplicatedStorage.guiEventA.OnClientEvent:Connect(function(plr)
local function typewrite(object,text,length)
for i = 1,#text,1 do
object.Text = string.sub(text,1,i)
wait(length)
end
end
typewrite(textlabel,"Ah... Seems like someone was able to find this tiny place. So what brings you here, sir?",0.01)
wait(1)
typewrite(textlabel,"There's not much to do here... But if you agree, you can help me with something.",0.01)
wait(1)
typewrite(textlabel,"About 15 years ago, I had a cerebral palsy during a ritual. Because of this cerebral palsy, I immediately forget what I went through. Since then, I have not been interested in rituals...",0.01)
wait(1)
typewrite(textlabel,"But there is a way to get over this disease. For this, I need some water brought from the sacred fountain on this mountain, which was built in ancient times.",0.01)
wait(1)
typewrite(textlabel,"If you bring me some of this water, I will try to help you with some stuff. Here's a small bottle you can put the water in.",0.01)
wait(1)
typewrite(textlabel,"And please be careful, the way to fountain is dangerous. I'll be praying for you...",0.01)
wait(2)
typewrite(textlabel," ",0.01)
end)
I tried to add a debounce to this local script, it worked but i cannot find a way to fix the problem about the tool.
Sorry if it was hard to understand, this is my first topic so it was a bit confusing, but if someone can help thanks a lot!
Thanks again!