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

Simple fire script won't change actual fire size?

I'm trying to make a fire get smaller and smaller periodically by using the Fire's Size property, and in the output it shows that the size is smaller and smaller but in game the fire appears to be the same size. Any thoughts?

local Campfire = script.Parent.Parent
local Fire = script.Parent.Fire
local Strength = Fire.Size

while true do
	print(Strength)
	wait(5)
	Fire.Size = Strength - 1
	
	if Strength == 0 then 
		Campfire:remove()
	end
end

3 answers

✓ Accepted answer

Your main problem is how variables behave. When you set a variable at the beginning, like you have local Strength = Fire.Size, then that variable is set once and never changes. You are using it like it is the current value of Fire.Size. This is a common early pitfall I've seen on here and the discord server.

Instead, you need to get the current value of Fire.Size and subtract 1 from that.

local Campfire = script.Parent.Parent
local Fire = script.Parent.Fire

while true do
    wait(5)
    Fire.Size = Fire.Size - 1

    if Strength <= 0 then 
        Campfire:Destroy()
    end
end

You have one other moderate problem and one other minor problem. First, :remove() is deprecated, don't use it, use :Destroy() instead. Second, you had if Strength == 0 then which might not always trigger if, for instance, later you set the fire's starting size to a decimal, like 5.5 because it will become 4.5 then 3.5, 2.5, 1.5, 0.5, -0.5 and it never became 0 preventing that code from running. That solution is also simple, just replace == with <=.

1 comment

0

Thanks!

The main problem is that you store the size of the fire in the variable Strength so Strength - 1 will be the same value in every loop.

Some other problems I have found is that, Size is in the range of 230 and Heat is in the range of 025. This information was from my own tests in studio though the wiki page does give different information.

Putting this all together:-

local Campfire = script.Parent.Parent
local Fire = script.Parent.Fire

while true do
    print(Fire.Size)
    wait(5)
	-- we use the current fire size and take one from it
    Fire.Size = Fire.Size - 1

    if Fire.Size == 2 then -- the new min fire limit
        Campfire:Destroy()
    end
end

I hope this helps.

4 comments

2

You left in :remove()

0

The prints way be from other scripts, the script that Gwolflover provided will only print the same value which was stored in the Strength variable

0

@GoldenPhysics ops lol thanks

0

Thanks!

Like above, strength is defined outside the loop, and you aren't changing it inside the loop so it will always stay the same. Instead, just change the fire.Size directly by:

Fire.Size = Fire.Size -1

Also use :Destroy() when removing the campfire. remove() is deprecated.

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