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

The UI doesn't appear when clicking, how to fix it?

Asked by 2 years ago

So I wanted to make an NPC that it's UI appears when you click on it's hair, But it doesn't appear. There are no errors and I'm not sure why it doesn't work!

what i wanted:

Click. The UI appears between milliseconds The text appears

what happened: Click. nothing appears text doesn't emit.

I am experiencing this issue at the Studio.

local dialog = game.Players.StarterGui.walkietalkie.talked
local who = dialog.Parent.who

script.Parent.MouseClick:Connect(function()
    for i = 1, 9 do
        wait(0.01)
        dialog.Transparency = dialog.Transparency - 0.11
        who.Transparency = who.Transparency - 0.11
    end

    wait(5)

    dialog.Text = "D"
    wait(0.05)
    dialog.Text = "Do"
    wait(0.05)
    dialog.Text = "Do y"
    wait(0.05)
    dialog.Text = "Do yo"
    wait(0.05)
    dialog.Text = "Do you"
    wait(0.05)
    dialog.Text = "Do you k"
    wait(0.05)
    dialog.Text = "Do you kn"
    wait(0.05)
    dialog.Text = "Do you kno"
    wait(0.05)
    dialog.Text = "Do you know"
    wait(0.05)
    dialog.Text = "Do you know w"
    wait(0.05)
    dialog.Text = "Do you know wh"
    wait(0.05)
    dialog.Text = "Do you know wha"
    wait(0.05)
    dialog.Text = "Do you know what"
    wait(0.05)
    dialog.Text = "Do you know what t"
    wait(0.05)
    dialog.Text = "Do you know what th"
    wait(0.05)
    dialog.Text = "Do you know what thi"
    wait(0.05)
    dialog.Text = "Do you know what this"
    wait(0.05)
    dialog.Text = "Do you know what this s"
    wait(0.05)
    dialog.Text = "Do you know what this sy"
    wait(0.05)
    dialog.Text = "Do you know what this sym"
    wait(0.05)
    dialog.Text = "Do you know what this symb"
    wait(0.05)
    dialog.Text = "Do you know what this symbo"
    wait(0.05)
    dialog.Text = "Do you know what this symbol"
    wait(0.05)
    dialog.Text = "Do you know what this symbol i"
    wait(0.05)
    dialog.Text = "Do you know what this symbol is"
    wait(0.05)
    dialog.Text = "Do you know what this symbol is?"
end)


Any answers appreciated!

2 answers

Log in to vote
0
Answered by 2 years ago
local dialog = game.Players.StarterGui.walkietalkie.talked
local who = dialog.Parent.who
local text = "Do you know what this symbol is?"

script.Parent.MouseClick:Connect(function()
    for i = 1, 9 do
        task.wait(0.01)
        dialog.Transparency = dialog.Transparency - 0.11
        who.Transparency = who.Transparency - 0.11
    end

    task.wait(5)

    for i = 1,#text,1 do
        dialog.Text = string.sub(text,1,i)
        task.wait(0.05)
    end
end
Ad
Log in to vote
0
Answered by 2 years ago
Edited 2 years ago

The first person who answered is right, but I'll explain it.

local text = "Do you know what this symbol is?"

function roundNumber(num,  numDecimalPlaces)
    return tonumber(string.format("%." .. (numDecimalPlaces or 0) .. "f", num))
end

script.Parent.MouseClick:Connect(function(player)
    local dialog = Player:WaitForChild(“PlayerGui”):WaitForChild(“walkietalkie”):WaitForChild(“talked”)
    local who = dialog.Parent:WaitForChild(“who”)

    for i = 1, 0, -0.1 do
        task.wait(0.1)
        dialog.Transparency = roundNumber(i, 1)
        who.Transparency = roundNumber(i, 1)
    end

    task.wait(5)

    for i = 1, #text, 1 do
        dialog.Text = string.sub(text, 1, roundNumber(i))
        task.wait(0.05)
    end
end

So for the first loop, which is for i = 1, 0, -0.1 do it makes the dialog appears gradually every 0.1 seconds when you click. A numeric for i loop consists of a minimum number, maximum number, and increment. An increment tells whether the minimum number should increase or decrease until it reaches the maximum number, and an increment also tells how much will the minimum number should add/subtract. Since the first loop increment is -0.1, the minimum number decreases by 0.1 until it reached the maximum number, zero. Zero transparency means the GUIObject is not transparent.

Also the wait() is getting deprecated by task.wait(). The reason why is because it is a lot faster, is more effective, and avoids throttling. (Idk what throttling means lol).

Then we have the second loop. Still the same, a min num, max num, and increment. But this time, it is adding up, because it does not have a negative sign. The reason why we need to add it up is that the more numbers, the more letters of the text are shown.

You use string.sub if you want the text to only show a specific number of letters. For example, you type "Hello" and you want to only show the first 3 letters. So you will type string.sub("Hello", 1, 3) and it will print as "Hel".

local stringSubbed = string.sub("Hello", 1, 3)
print(stringSubbed) -- > Hel

Since the second number is how long you want the text to be, the first number is what letter of the text in order you want to start. For example, you want to cut off the first 2 letters of "Welcome" and start at "L" which is the 3rd letter. So you type string.sub("Welcome", 3) and it will print "lcome".

local stringSubbed = string.sub("Welcome", 3)
print(stringSubbed) -- > lcome

You can also use string.sub in a loop to make a smooth typewriting effect in texts.

Also, I put a new function in your script to get an estimate of the number.

That's all! I hope you have a great day and I also hope that you understood my explanations. Bye! ^^

Answer this question