So I made a script where when a player touches a block a textlabel appears, it works perfectly fine except that it glitches because the player touches it to many times, even though they touch it once the output still says Player Touched(x12) so that means the player touched it 12 times.
Sorry if that is hard to understand, I am not good at explaining things.
server script:
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid")then
game.ReplicatedStorage.Popup2:FireClient(game.Players:GetPlayerFromCharacter(hit.Parent))
end
end)
local script: (makes the textlabel appear)
local playername = game.Players.LocalPlayer.Name
game.ReplicatedStorage.Popup2.OnClientEvent:Connect(function()
game.Players.LocalPlayer.PlayerGui.PlayGui.TextLabel.Visible = true
wait(0.1)
sentences = {
"I remember this place.. It is my home?",
"I remember a bit of that day in the lab.... I was looking at a scientist.",
"WHAT EVER IS HAPPENING NEEDS TO STOP!!!"
}
--Displays current sentence with type writer effect
function displaySentence(sentence)
for i = 1, #sentence do
game.Players.LocalPlayer.PlayerGui.PlayGui.TextLabel.Text = string.sub(sentence, 1, i)
wait(0.1) -- Speed of the text Typewriter animation
end
end
--loop thru all the sentences, displaying each sentence
--with a 1 second pause in between each sentence
for _, sentence in pairs(sentences) do
displaySentence(sentence)
wait(1)
end
wait(3)
script.Parent.TextLabel.Visible = false
end)
local script: (destroys the block afterward)
game.ReplicatedStorage.Popup2.OnClientEvent:Connect(function()
print ("Player Touched")
game.Workspace.TouchPart2:Destroy()
end)

1 comment
Add a debounce