Hey! I’m trying to stop a loop (typewriter effect) from a different script, using a BoolValue. However, it doesn’t really work. Once you stop touching the hitreg part, it does go invisible and tweens away, but the text (typewriter effect) still keeps on going. If you then enter again, 2 or more texts (typewriter effects) collide with each other.
ModuleScript
local module = {}
function module.typeWrite(object, text, length, sound)
local player = object.Parent.Parent.Parent.Parent
local TypewriterDebounce = player.ConstructionFolder.TypewriterDebounce
if TypewriterDebounce.Value == true then
for i = 1, #text do
if TypewriterDebounce.Value == true then
object.Text = string.sub(text,1,i)
sound:Play()
task.wait(length)
elseif TypewriterDebounce.Value == false then
object.Text = ""
sound:Stop()
break
end
end
end
end
return module
ServerScript
local dialogueDebounce = false
local progressDebounce = false
local TypewriterModule = require(script.ModuleWriter)
local writeSound = script.Typewriter
local RS = game:GetService("ReplicatedStorage")
local EffectEvent = RS:WaitForChild("ConstructionSoundBlur")
script.Parent.Touched:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
local HasAcceptedYet = player:WaitForChild("ConstructionFolder").HasAcceptedYet
local TypewriterDebounce = player:WaitForChild("ConstructionFolder").TypewriterDebounce
if HasAcceptedYet.Value == false then
if dialogueDebounce == false then
local gui = player.PlayerGui:WaitForChild("EventDialogue")
TypewriterDebounce.Value = true
gui.Holder.Visible = true
gui.Holder:TweenPosition(UDim2.new(0.5, 0, 0.73, 0), "In", "Linear", 1, true, nil)
dialogueDebounce = true
task.wait(1)
gui.Holder.Header.Visible = true
gui.Holder.DialogueText.Visible = true
task.wait(1)
local yesButton = gui.Holder.Yes
local noButton = gui.Holder.No
local object = gui.Holder.DialogueText
if TypewriterDebounce.Value == true then
TypewriterModule.typeWrite(object, "Yo! I'm Frank, the Construction Manager.", writeSound.TimeLength, writeSound)
wait(2)
TypewriterModule.typeWrite(object, "We are tasked with constructing a new building, but we won't finish in time!", writeSound.TimeLength, writeSound)
wait(3)
TypewriterModule.typeWrite(object, "We need your help constructing the building.", writeSound.TimeLength, writeSound)
wait(2)
TypewriterModule.typeWrite(object, "Do you accept this offer?", writeSound.TimeLength, writeSound)
wait(0.5)
yesButton.Visible = true
noButton.Visible = true
yesButton:TweenPosition(UDim2.new(0.162, 0, 1.214, 0), "In", "Linear", 0.5, true, nil)
noButton:TweenPosition(UDim2.new(0.562, 0, 1.214, 0), "In", "Linear", 0.5, true, nil)
end
wait(0.5)
noButton.MouseButton1Click:Connect(function()
gui.Holder.DialogueText.Text = ""
yesButton:TweenPosition(UDim2.new(0.162, 0, 3, 0), "In", "Linear", 0.2, true, nil)
noButton:TweenPosition(UDim2.new(0.562, 0, 3, 0), "In", "Linear", 0.2, true, nil)
wait(0.2)
yesButton.Visible = false
noButton.Visible = false
end)
yesButton.MouseButton1Click:Connect(function()
yesButton:TweenPosition(UDim2.new(0.162, 0, 3, 0), "In", "Linear", 0.2, true, nil)
noButton:TweenPosition(UDim2.new(0.562, 0, 3, 0), "In", "Linear", 0.2, true, nil)
wait(0.2)
yesButton.Visible = false
noButton.Visible = false
TypewriterModule.typeWrite(object, "Thanks for your help!", writeSound.TimeLength, writeSound)
wait(2)
TypewriterModule.typeWrite(object, "To manage your tasks, click on the orange star button.", writeSound.TimeLength, writeSound)
wait(2)
TypewriterModule.typeWrite(object, "That's all, good luck!", writeSound.TimeLength, writeSound)
end)
end
elseif HasAcceptedYet.Value == true then
if progressDebounce == false then
local gui = player.PlayerGui:WaitForChild("ConstructionGui")
local sound = player.PlayerGui.HUD.Sidebar.Container.Construction.LocalScript.ClickSound
gui.Holder.Visible = true
gui.Holder:TweenPosition(UDim2.new(0.5, 0, 0.5, 0), "In", "Elastic", 1, true, nil)
EffectEvent:FireClient(player, 15)
task.wait(1)
progressDebounce = true
end
end
end
end)
script.Parent.TouchEnded:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
if player:FindFirstChild("PlayerGui") then
local HasAcceptedYet = player:WaitForChild("ConstructionFolder").HasAcceptedYet
local TypewriterDebounce = player:WaitForChild("ConstructionFolder").TypewriterDebounce
if HasAcceptedYet.Value == false then
if dialogueDebounce == true then
local gui = player.PlayerGui:WaitForChild("EventDialogue")
gui.Holder.DialogueText.Text = ""
gui.Holder.Header.Visible = false
gui.Holder.DialogueText.Visible = false
gui.Holder.Yes.Visible = false
gui.Holder.No.Visible = false
TypewriterDebounce.Value = false
gui.Holder:TweenPosition(UDim2.new(0.5, 0, 1.5, 0), "In", "Linear", 1, true, nil)
task.wait(1)
gui.Holder.Visible = false
dialogueDebounce = false
end
elseif HasAcceptedYet.Value == true then
if progressDebounce == true then
local gui = player.PlayerGui.ConstructionGui
local sound = player.PlayerGui.HUD.Sidebar.Container.Construction.LocalScript.ClickSound
gui.Holder:TweenPosition(UDim2.new(0.5,0,1.5,0), 'InOut', 'Elastic', 1)
EffectEvent:FireClient(player, 0)
task.wait(0.8)
progressDebounce = false
end
end
end
end
end)