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

Working with MouseButton1Down, need help and advice [?]

Asked by 7 years ago

This is a script of what I'm trying to do;

local plr = game.Players.LocalPlayer
local Continue = plr:WaitForChild("Stats").Continue
local NB = script.Parent

NB.MouseButton1Down:connect(function()
    if Continue.Value == true then
        local WTS = script.Parent.Parent:WaitForChild("TextBubble").WhatToSay
        local Arrow = script.Parent.Parent.Parent:WaitForChild("MainFrame").Arrow
        --Animating the Arrow
        Arrow:TweenPosition(UDim2.new(0, 130,0, 160),'In','Sine',3)
        WTS.Value = ""
        wait()
        WTS.Value = "First, let's take a look at the Income bar! The Income bar show's how much Coins you get per the amount of time. You can upgrade the time stat in the shop. Upgrading it will just decrease the time."
        NB.MouseButton1Down:connect(function()
            WTS.Value = "Hey, why don't we play an obby? We might win some rare rewards!"
        end)
    end
end)


The problem is if I click the button one time it will repeat, What I'm trying to do is The first time the player clicks the NB button it will change WTS.Value to "First, let's take a look at the Income bar! The Income bar show's how much Coins you get per the amount of time. You can upgrade the time stat in the shop. Upgrading it will just decrease the time." Then when the player clicks the NB Button again it will change the value. Though right now if you take a look it is pretty obvious that When I click the NB Button 1 time it will run both codes. How would I fix this? Any advice or tips are appreciated. Thanks

1 answer

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

Hey BlackOrange3343,

There is one way that I would do your code which I believe to be an easy way is: Using tables to store text and indexing them. Below is what you need to make happen in english.

--[[
    Store all of the text inside of a table. (Make sure it's in order of what you want to come first 
    and what you want next. 

    Set a variable equal to 1 and add 1 to it every time the player clicks. 

    Index through the table using that variable.
--]]

That's about the best way I can describe what you need to make happen. Below is a personal example of what I said.

local texts = {
             "Hey, how are you doing today?",
             "I'm doing fine, how about you?"
            }
local button = script.Parent
local i = 1

button.MouseButton1Down:Connect(function()
    local text = texts[i];

    button.Text = text
    i = i + 1
end)

Well, there you have it. If I were you, I'd have a boolean value check at the beginning of the function if that value is true or false and when you're done with all the dialog just make that value opposite to what you are checking at the beginning of the function. That way, you will have closed the function so it won't error saying that there isn't a text in this index of the table because, if you keep adding 1 to 'i' eventually it's gonna make it to a high enough number to where there is no index for it in the table.

Well, I hope I helped in one way or another and have a great day/night.

~~ KingLoneCat

Ad

Answer this question