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

Explosion Positioning, how?

Asked by
Nidoxs 190
9 years ago

This doesn't place an explosion where I want it. Her is the output: Model.Script:50: attempt to perform arithmetic on field 'new' (a function value)

script.Parent.leverOn.Part1.Transparency = 1 
    script.Parent.leverOn.Part2.Transparency = 1  
    script.Parent.leverOn.Part3.Transparency = 1   
    script.Parent.leverOn.Part4.Transparency = 1
    script.Parent.leverOn.Click.Transparency = 1  
    script.Parent.leverOn.Part1.CanCollide = false
    script.Parent.leverOn.Part2.CanCollide = false
    script.Parent.leverOn.Part3.CanCollide = false    
    script.Parent.leverOn.Part4.CanCollide = false
    script.Parent.leverOn.Click.CanCollide = false 


local isOn = true

function on()
    isOn = true
    script.Parent.leverOff.Part1.Transparency = 1 
    script.Parent.leverOff.Part2.Transparency = 1  
    script.Parent.leverOff.Part3.Transparency = 1   
    script.Parent.leverOff.Part4.Transparency = 1
    script.Parent.leverOff.Click.Transparency = 1  
    script.Parent.leverOff.Part1.CanCollide = false
    script.Parent.leverOff.Part2.CanCollide = false 
    script.Parent.leverOff.Part3.CanCollide = false    
    script.Parent.leverOff.Part4.CanCollide = false
    script.Parent.leverOff.Click.CanCollide = false 
    script.Parent.leverOn.Part1.Transparency = 0 
    script.Parent.leverOn.Part2.Transparency = 0  
    script.Parent.leverOn.Part3.Transparency = 0   
    script.Parent.leverOn.Part4.Transparency = 0
    script.Parent.leverOn.Click.Transparency = 0  
    script.Parent.leverOn.Part1.CanCollide = true 
    script.Parent.leverOn.Part2.CanCollide = true 
    script.Parent.leverOn.Part3.CanCollide = true    
    script.Parent.leverOn.Part4.CanCollide = true
    script.Parent.leverOn.Click.CanCollide = true 
    script.Parent.leverOff.Lever:Play() 
    wait(2) 
    script.Parent.leverOff.Man:Play() 
    wait(1.5) 
    script.Parent.leverOff.Siren:Play() 
    wait(25) 
    script.Parent.leverOff.Explode:Play() 
    Instance.new("Explosion", script.Parent.Parent.Rotor.Rotor) 

script.Parent.Parent.Rotor.Rotor.Explosion.BlastPressure = 1.79769e+308 
script.Parent.Parent.Rotor.Rotor.Explosion.BlastRadius = 100 
script.Parent.Parent.Rotor.Rotor.Explosion.Position = Vector3.new-181.343, 65.794, -48.842
end
function off()
    isOn = false
    script.Parent.leverOff.Part1.Transparency = 0 
    script.Parent.leverOff.Part2.Transparency = 0  
    script.Parent.leverOff.Part3.Transparency = 0   
    script.Parent.leverOff.Part4.Transparency = 0
    script.Parent.leverOff.Click.Transparency = 0  
    script.Parent.leverOff.Part1.CanCollide = true
    script.Parent.leverOff.Part2.CanCollide = true
    script.Parent.leverOff.Part3.CanCollide = true   
    script.Parent.leverOff.Part4.CanCollide = true
    script.Parent.leverOff.Click.CanCollide = true
    script.Parent.leverOn.Part1.Transparency = 1 
    script.Parent.leverOn.Part2.Transparency = 1  
    script.Parent.leverOn.Part3.Transparency = 1   
    script.Parent.leverOn.Part4.Transparency = 1
    script.Parent.leverOn.Click.Transparency = 1  
    script.Parent.leverOn.Part1.CanCollide = false
    script.Parent.leverOn.Part2.CanCollide = false 
    script.Parent.leverOn.Part3.CanCollide = false   
    script.Parent.leverOn.Part4.CanCollide = false
    script.Parent.leverOn.Click.CanCollide = false
end

function onClicked()

    if isOn == true then off() else on() end
end 

script.Parent.leverOff.Click.ClickDetector.MouseClick:connect(on)
script.Parent.leverOn.Click.ClickDetector.MouseClick:connect(off)


off()

1 answer

Log in to vote
2
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
9 years ago

Your main error is

script.Parent.Parent.Rotor.Rotor.Explosion.Position = Vector3.new-181.343, 65.794, -48.842

Hopefully this is just a typo, but when you use the Vector3.new constructor you must put the three coordinates inside parenthesis.

Vector3.new(x#, y#, z#)

Although this is most likely what causes your error, your code is not very efficient. Instead of repeating all your code over and over again, it is recommended that you use a for loop. For example:

Instead of,

game.Workspace.Model.Part1.Transparency = 1
game.Workspace.Model.Part2.Transparency = 1
game.Workspace.Model.Part3.Transparency = 1
game.Workspace.Model.Part4.Transparency = 1

Consider,

for index,child in pairs(game.Workspace.Model:GetChildren()) do
    child.Transparency = 1
end

Here we just made the code more efficient and much shorter. Another example:

Instead of,

game.Workspace.Part.Transparency = 0.2
wait(0.1)
game.Workspace.Part.Transparency = 0.4
wait(0.1)
game.Workspace.Part.Transparency = 0.6
wait(0.1)
game.Workspace.Part.Transparency = 0.8
wait(0.1)
game.Workspace.Part.Transparency = 1

Consider,

for i = 0,1,-0.01 do
    game.Workspace.Part.Transparecy = i
    wait()
end

Here not only did we make the code shorter and more efficient, we also made the fading less choppy and more smooth. Try to integrate some of these things into your code and feel free to ask questions.

0
Just pointing out that you put z instead of x on the first value on this snippet of code: "Vector3.new(z#, y#, z#)". Spongocardo 1991 — 9y
0
Thanks, guess I really should proof read my stuff. Perci1 4988 — 9y
0
Wow! Thanks alot, you're amazing! Good tips! :D Nidoxs 190 — 9y
Ad

Answer this question