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

"Sign" is not responding at all, even though output is now showing any errors?

Asked by 7 years ago

So, to make it really quick, a sign repeats 3 lines, until someone steps on the block. After the person steps off the block, the while loops should resume. The script is inside the block that I touch. Any ideas why it's not working?

local x = 1
local p = game.Workspace.bo.SurfaceGui.TextBox.Text

while x == 1 do


    p = ("Step right up!")
    wait(3)
    p = ("Don't be shy, now!")
    wait(3)
    p = ("Step on that green plate there, and be amazed!")
    wait(3)

end

local db = true

function dif (hit)
    local h = hit.Parent:FindFirstChild("Humanoid")
    if h then

        x = 2
        db = false

        p = ("Good boy!")

        wait(2)

        db = true
    end
end

    script.Parent.Touched:connect(dif)

1 answer

Log in to vote
2
Answered by 7 years ago

There are a few things we have to fix in your script.

First off, at line 2:

local p = game.Workspace.bo.SurfaceGui.TextBox.Text

What's happening here is that p is now a string, and this string will be what's written in the Text property. If you directly change the value of p to, for example:

p = "Step right up!"

What will happen is that it will change what the value of p is, and it will not change what the sign is saying. To change what the sign is saying, you have to do this:

local p = game.Workspace.bo.SurfaceGui.TextBox

p.Text = "Step right up!"

Another thing is that you don't change values of variables and properties between () (Atleast from my knowledge).

Now, to the while loop:

while x == 1 do
    p = ("Step right up!")
    wait(3)
    p = ("Don't be shy, now!")
    wait(3)
    p = ("Step on that green plate there, and be amazed!")
    wait(3)
end

What's happening here is that currently, x is equal to 1 and so, your code will start running the while loop. But now, your code is stuck in the while loop, and it will not run anything below it.

So what you can do is to put the while loop in a different thread, and so the code will run the while loop and the other stuff below it.

spawn(function()
    while x == 1 do


        p = ("Step right up!")
        wait(3)
        p = ("Don't be shy, now!")
        wait(3)
        p = ("Step on that green plate there, and be amazed!")
        wait(3)

    end
end)

Another problem that rises with the while loop is that the loop will not instantly stop if x is not equal to 1.

So for example, in the sign it's showing "Don't be shy now!". When that happens, the player presses the button and x is not equal to 1 anymore. But that doesn't mean the while loop will stop working, it will still wait those 3 seconds, show "Step on that green plate there, and be amazed!" wait another 3 seconds and then finally the while loop will stop working.

So to fix that problem I suggest doing:

spawn(function()
    --A list of messages that will show up
    local messages = {
        "Step right up!",
        "Don't be shy, now!",
        "Step on that green plate there, and be amazed!"
    }

    --Loop
    while x == 1 do
        --This is a loop that will loop 3 times (because "messages" has 3 items)
        for i = 1, #messages do
            --Return if x is not 1. When you return, the code will stop here
            if x ~= 1 then return end

            --Show the message
            p.Text = messages[i]

            --Delay for 3 seconds
            wait(3)
        end
    end
end)

I hope I solved your problem and helped.

Ad

Answer this question