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

Making a "when ____, then" script (waits until request is met, then execute command)?

Asked by 5 years ago
Edited 5 years ago

I'm trying to make a script that waits until a requirement is met, and then the command runs. For example, when a server collectively earns a certain amount of points, a message changes. I'm a beginner with scripting, and I feel that knowing how to do this will be useful. I've tried using if/elseif statements, although it never works properly.

local points = game.Workspace.Total.Value

while true do
wait (0.5)
if points > 299 then
    script.Parent.Text = "Message #3"
    end
elseif points > 199 then
    script.Parent.Text = "Message #2"
    end
elseif points > 99 then
    script.Parent.Text = "Message #1"
    end
end

In the example scenario, when the server reaches 100 points, a textbox changes revealing a message. And again when they reach 200, 300, and so on.

In the output, I'm being told I'm missing an "end" to close the "while true do", but no matter how I change up the indents in the code or the "end"s, it still doesn't seem to work.

I know this is completely wrong, but I can't find anything across the internet whatsoever. If anybody knows a solution to this or where I can find one, it would be greatly appreciated. Finally, if I'm breaking any rules without knowing it, I apologize, and I will fix that in my next post.

Thanks, Elliott

0
There will be only one end. One for the `while true do` loop and one for the `if` statement. Note that you don't have to add more ends to `elseif` statements because they are connected with the `if` statement hellmatic 1523 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

All your ends should be at the bottom. Also you shouldn't use while true do to check for a change. I've remade your script below.

local IntValue = game.ServerStorage.IntValue -- Or Wherever the value is located
IntValue.Changed:Connect(function()
if IntValue.Value > 299 then
    script.Parent.Message = "Message #3"
elseif
    IntValue.Value > 199 then
        script.Parent.Message = "Message #2"
elseif
        IntValue.Value > 99 then
            script.Parent.Message = "Message #1"
            end
        end
    end
end)
Ad

Answer this question