Hello, I have this code:
local debounce = false
local textQueue = {"First Text", "Second Text", "Third Text"}
local currentIndex = 1
local waitTime = 5
local function displayNextText(player)
local playergui = player:WaitForChild("PlayerGui")
local textbox = playergui.PopUp2.Text
textbox.Text = textQueue[currentIndex]
textbox.Fade:FireClient(player)
currentIndex = currentIndex % #textQueue + 1
end
local function startTextDisplay()
while true do
wait(waitTime)
for _, player in ipairs(game.Players:GetPlayers()) do
displayNextText(player)
end
end
end
script.Parent.Touched:Connect(function(hit)
if not debounce then
debounce = true
if hit.Parent:FindFirstChild("Humanoid") then
local character = hit.Parent
local player = game.Players:GetPlayerFromCharacter(character)
if player then
displayNextText(player)
spawn(startTextDisplay)
end
end
debounce = false
end
end)
The bahvior I’m looking to achieve is that when the player touches the part once, the texts start showing up even if I don’t touch the part, and the texts show only once.
Currently, the issue I’m having is that the text continously show up when I touch the part and they depend on the part.
How can I fix this?