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

How do I make it so when a part is a certain size, certain scripts stop working?

Asked by 5 years ago
Edited 5 years ago

I'm trying to make a machine that shoots fire when enabled and stops when disabled, but I want it to have fuel so when it runs out it shuts off. But when I tried to test it kept saying: " Expected ')' (to close at column 26) got ')' " I tried multiple things, but nothing worked.

if script.Parent.Size == (0.63, 0, 1.69) then
    workspace.Roaster.KillBrick.Fire:Stop()
    workspace.Roaster.KillBrick.Facer.Disabled = true
    workspace.Roaster.KillBrick.Script.Disabled = true
    workspace.Roaster.KillBrick.FireS.Disabled = true
    workspace.Roaster.Model.Model.Script.Disabled = true

    workspace.RLIGHTS.Green.Transparency = .3
    workspace.RLIGHTS.Green.Material = Enum.Material.Glass

    workspace.RLIGHTS.Red.Transparency = .3
    workspace.RLIGHTS.Red.Material = Enum.Material.Glass

    workspace.RLIGHTS.Yellow.Material = Enum.Material.Neon
    workspace.RLIGHTS.Yellow.Transparency = 0
end
if script.Parent.Size >= (0.63, 0, 1.69) then
    workspace.RLIGHTS.Yellow.Material = Enum.Material.Glass
    workspace.RLIGHTS.Yellow.Transparency = .3

    workspace.RLIGHTS.Red.Transparency = 0
    workspace.RLIGHTS.Red.Material = Enum.Material.Neon

    workspace.Roaster.Model.Model.Script.Disabled = false
end

I'm also pretty sure there's a more beautiful way to do this, but this is all I've got. Thanks in advance if you can help!

0
You have to add ) under the last end I think eloiishot 47 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

You cannot compare Vector3s with a list of numbers (even if you put them in parentheses), you have to specifically create a Vector3. ex, your first line should be if script.Parent.Size == Vector3.new(0.63, 0, 1.69) then

Line 17 is a bigger problem because you cannot perform >= on Vector3s, only on the x/y/z values.

Another concern is that if you change the size of script.Parent by adding/subtracting a value repeatedly, "==" is likely to return false when you would expect it to return true -- this is because computers don't handle decimal values well (due to how they represent fractional binary). You can test this for yourself with this script in the command bar: n = 0; for i = 1, 10 do n = n + 0.1 end print(n, n == 1, n-1) -- it will print "1 false -1.1102230246252e-16" -- "n" is actually a value slightly different than 1; Roblox is just rounding it for you in the output.

Thus, I would recommend keeping track of a 'fuel' variable. Change script.Parent.Size based on the amount of fuel left; decide what to do on lines 1 and 17 based on fuel. You could do fuel == 0 on the first line if, when decreasing the fuel, you set it to 0 if the fuel becomes negative.

0
For the fuel becoming negative thing math.clamp exists to clamp the value in between two numbers. User#19524 175 — 5y
Ad

Answer this question