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

How to make message only pop up one time?

Asked by 5 years ago

I am trying to make this message script only pop up one time. It works when the player touches the block and a message pops up. When the message is over and the player touches the block again it shows pops up again which is not what I want. Any help?

01function message(m)
02 
03 
04 
05---------------------------------------------------------------\\
06 
07 
08m.Text = "How do I make you pop up once?"
09wait(5)
10 
11 
12 
13 
14---------------------------------------------------------------//
15 
View all 69 lines...
0
I mean, you could remove the part you're using to trigger this once the message is finished and you're done displaying it. Though that may not be the best way. shipleydog2 -3 — 5y

3 answers

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

Put a variable at the top like this:

1local activated = false
2 
3function message(m)
4    if activate == false then
5        activated = true
6        m.Text = "How do I make you pop up once?"
7        wait(5)
8    end
9end
Ad
Log in to vote
0
Answered by
Elyzzia 1294 Moderation Voter
5 years ago
Edited 5 years ago

since you're connecting to an event, you can disconnect the function once you're done with RBXScriptConnection:Disconnect()

in your code, that would look something like this:

01local connection -- define the variable before the function, because the function needs to be able to access it
02local activated = false -- if you need to know if the part was touched for whatever reason
03 
04local function onTouch(hit)
05    if whatever then
06        if blahBlahBlah then
07            -- stuff goes here
08            activated = true
09            connection:Disconnect()
10        end
11    end
12end
13connection = script.Parent.Touched:Connect(onTouch) -- when you Connect to an event, it returns an RBXScriptConnection which you can use to disconnect the function later

also, make sure you put local whenever you define a variable or function

why? it's good practice

why is it good practice? it's faster when you do that, also there's global environment blah blah blah whatever It's Not Good stuff but i'm not advanced enough to tell you why global environment is bad

Log in to vote
0
Answered by
haba_nero 386 Moderation Voter
5 years ago

Hello! I can see your issue! I'd suggest using tables to store players that have already touched the brick, like so:

01function message(m)
02 
03 
04 
05---------------------------------------------------------------\\
06 
07 
08m.Text = "How do I make you pop up once?"
09wait(5)
10 
11 
12 
13 
14---------------------------------------------------------------//
15 
View all 78 lines...

If you have any questions, comment below!

Best,

TheLastHabanero

Answer this question