Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I make this textlabel not glitch when a player touches a block?

Asked by
bailley5 114
4 years ago
Edited 4 years ago

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)
0
Add a debounce mixgingengerina10 223 — 4y

1 answer

Log in to vote
1
Answered by
Misqueso 145
4 years ago

You can delete the block as soon as you touch it.

You can also add a variable that prevents a player from viewing the same thing twice. Something like:

local playername = game.Players.LocalPlayer.Name

local debounce = false

game.ReplicatedStorage.Popup2.OnClientEvent:Connect(function()
    if debounce then return end --Stops if debounce is already true
    debounce = true
    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)

I apologize for fixing your spacing.

0
Tysm! bailley5 114 — 4y
Ad

Answer this question