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

How to increase the size of a part when a variable reaches a certain number?

Asked by
Ma02rc 4
6 years ago
Edited 6 years ago

Hello scripters that are better than me, I am trying to make a script where if the temperature value reaches a certain amount, coresize value increases until it reaches 20. The coresize value should increase the size of a part. Here is what I tried:

temperature = 200
coresize = 4
if true then
    wait(3)
    temperature = temperature +5
end

if temperature >= 210 then
    coresize = coresize + 1
    script.Parent.Size.X = coresize
    script.Parent.Size.Y = coresize
    script.Parent.Size.Z = coresize
repeat until coresize == 20
end

Any help is much appreciated =)

2 answers

Log in to vote
0
Answered by 6 years ago
temperature = 200
maxtemperature = 210
coresize = 4

while wait(3) do
    temperature = temperature +5
    if temperature >= maxtemperature then
    script.Disabled = true
    repeat
        coresize = coresize + 1
        script.Parent.Size.X = coresize
        script.Parent.Size.Y = coresize
        script.Parent.Size.Z = coresize
    until coresize == 20
   end
end
0
Hello FlamingGamez. I want to thank you for your contribution. I have tested the script, and with a few modifications, it worked! I decided to removed the script.Parent.Size part and replace it with a Vector3 script. Once again, thanks! Ma02rc 4 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

Though I understand your question, your attempt at solving it very much confused me, so I will show you an example of how I would do it and explain as I go. The code below assumes that the script is within a part inside the Workspace.

--We create our values as instances, unlike your variables above

local temperature = Instance.new("IntValue")
temperature.Parent = script.Parent
temperature.Value = 200
temperature.Name = "temperature"
local coresize = Instance.new("IntValue")
coresize.Parent = script.Parent
coresize.Value = 4
coresize.Name = "coresize"
local TempBeforeChange = 201 --The value that will trigger the event

temperature.Changed:Connect(function(prop) --Fires when the value changes
    if temperature.Value >= TempBeforeChange then
        for i = coresize.Value,20 do --Loop from coresize to 20
            wait()
            coresize.Value = i
            script.Parent.Size = Vector3.new(coresize.Value,coresize.Value,coresize.Value)
        end
    end
end)

You can change this at your own desire, as it was just an example!

0
Hello gioni01. Thank you so much for submitting an answer, I appreciate it a lot. I do have a question, though. When I placed in the script, nothing happened. I looked through the script, and I did not see anything that alters the "temperature.Value" Would I have to add some extra lines to the script? Ma02rc 4 — 6y
0
Nothing alters the temperature value in the given code except for your own changes to the variable. That was just an example. Gey4Jesus69 2705 — 6y

Answer this question