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

Why won't the transparency change when the 'while' criteria is met?

I am trying to make a simple fire decay script, which will allow the user to 'destroy' certain blocks when they use a special tool to set them on fire, which is visualised by the object getting more transparent over time until it's completely invisible.

if script.Parent.Fire.Enabled then
	for i=0, 1, 0.1 do
		wait(0.5)
		script.Parent.Transparency = "i"
	end
	if script.Parent.Transparency == 0 then
		script.Parent:Destroy()
	end
end

So far I have got this, which I thought would work, however in testing it only caught fire, and the transparency of the block would not change, I cannot see anything wrong with it, and I have tried to write the value for transparency in many different ways, such as in brackets and on its own.

EDIT:

while script.Parent.Fire.Enabled == true do
	wait()
	script.Parent.Light:Play()
	script.Parent.Crackling:Play()
	for i=0, 1, 0.1 do
		wait(0.5)
		script.Parent.Transparency = i
		if script.Parent.Transparency == 0 then
			script.Parent:Destroy()
			script.Parent.Crackling:Stop()
		end
	end
end

I have changed the script a bit, and it still does not carry out any single one of these commands when the block's fire is enabled... help!

2 answers

✓ Accepted answer

As for your first script, "i" means the letter i. If you want the variable i, just use i.


The second script runs like this:

  • Am I on fire? If so, do this stuff...
  • Am I still on fire? If so do this stuff...
  • OK I'm not on fire.

The problem is that if it starts disabled, the while loop will simply skips to that last step: "OK, I'm not on fire".

If you want to wait until you are on fire, the most straightforward to do to that is with a repeat loop:

repeat
	wait()
until script.Parent.Fire.Enabled

The if inside the for loop doesn't really make sense. You probably just want the stuff inside the if to always happen after the for.

Ok so right now the script just executes once and done so to fix this we need to add a loop to the script so add

while wait() do
	your code
end

now this will run your code until it destroys the script

3 comments

0

I have tried this, and the block's transparency still doesn't seem to change at all :I

0

ok that should help

0

That did indeed help, thanks a lot!

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