Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

moving brick in a while true do script?

So I have this script,

local count = script.Parent.Height.Value
wait(3)
while true do
	if count < 7.5 then
		script.Parent.CFrame=script.Parent.CFrame+Vector3.new(0,0.1,0)
		count = count + 0.1
		wait(0.1)
	else
			if count >= 7.5 then
		script.Parent.CFrame=script.Parent.CFrame+Vector3.new(0,-7.5,0)
		count = 7.5
	end

but it doesnt work at the top line 'count' is a number value under the same group as the brick(the scripts parent)

the 'end' on the bottom line is underlined in red and says "expected 'end' (to close 'else' at line nine), got

I dont understand whats wrong? the idea is that the scripts parent gets raised in increases of .1 every 0.1 seconds until the height reaces 7.5 in which case it should lower the part by 7.5 studs and continue the proccess

2 answers

✓ Accepted answer

You were missing an "end". That's the error you got. The while loop needs an end to determine where the loop stops. Also don't put .Value in a variable, I corrected that in the code.

local count = script.Parent.Height
wait(3)
while true do
    if count.Value < 7.5 then
        script.Parent.CFrame=script.Parent.CFrame+Vector3.new(0,0.1,0)
        count = count + 0.1
        wait(0.1)
    else
            if count.Value >= 7.5 then
        script.Parent.CFrame=script.Parent.CFrame+Vector3.new(0,-7.5,0)
        count = 7.5
    end
end

1 comment

0

thx alot

You forgot to put end after line 12 and dont use .Value in variables.

Here is the fixed script:

local count = script.Parent.Height
wait(3)
while true do
    if count.Value < 7.5 then
        script.Parent.CFrame=script.Parent.CFrame+Vector3.new(0,0.1,0)
        count.Value = count.Value + 0.1
        wait(0.1)
    else
            if count.Value >= 7.5 then
        script.Parent.CFrame=script.Parent.CFrame+Vector3.new(0,-7.5,0)
        count.Value = 7.5
    end
end

Hope it helped :)

4 comments

0

i beat u :p

0

lmao, I did not analyze right, I just ran to answer xD

0

you're tryna steal all that easy rep, dw if he gives me answer ill +rep yours lol

0

I'm trying to get back active here, but I do not have much free time :v

This discussion is preserved as it was. New answers, comments, and votes are closed.