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

My Parts Won't Function The Way I am Trying to Do, What did I do Wrong?

Asked by 5 years ago

I made two parts. One as the turn on and off button and the other to click to shoot button. Well, the problem is that, every time I click it, it does go down, but instead when I hit the shoot button, the other button goes down rather than staying down. I want the ActivateShoot part to be the on/off button for the other part. So let's say I turn on the ActivateShoot button, what it should do is go down to the position that I put and function the Shoot part. And if I click the ActivateShoot part again, it will be off and the Shoot part will not work, as in disabled unless you turn it back on. I hope I am being clear to what I am trying to do here. Sorry for the confusion!

-- Combining the Shoot and Activation --
AS = script.Parent.Parent.ActivateShoot
asOn = false
Shoot = script.Parent.Parent.Shoot
shootOn = false

function onClicked()
    if not asOn then
        asOn = true
    AS.CFrame = AS.CFrame+Vector3.new(0,-0.09,0)
    AS.BrickColor = BrickColor.new("Shamrock")
    shootOn = true
    Shoot.CFrame = Shoot.CFrame+Vector3.new(0,-0.09,0)
    Shoot.BrickColor = BrickColor.new("Shamrock") 
    wait(0.05)
    Shoot.CFrame = Shoot.CFrame+Vector3.new(0,0.09,0)
    Shoot.BrickColor = BrickColor.new("Bright red") 
    elseif asOn then
        asOn = false
    AS.CFrame = AS.CFrame+Vector3.new(0,0.09,0)
    AS.BrickColor = BrickColor.new("Bright red")
    shootOn = false
        end
    end

script.Parent.Parent.ActivateShoot.ClickDetector.MouseClick:connect(onClicked)
script.Parent.Parent.Shoot.ClickDetector.MouseClick:connect(onClicked)

1 answer

Log in to vote
1
Answered by 5 years ago

Your Shoot button is calling the same function as ActivateShoot. When you click the Shoot button while asOn is on, it'll go to line 18 elseif asOn then and make asOn and shootOn false.

You have two different commands, so you need to separate the instructions.

function onActivateClicked()
    if not asOn then --if asOn is off, turn it on
        asOn = true
        --other code
    elseif asOn then --if asOn is on, turn it and shootOn off
        asOn = false
        --other code
        shootOn = false
    end
end

function onShootClicked()
    if asOn then
        --shoot code
    end
end

script.Parent.Parent.ActivateShoot.ClickDetector.MouseClick:connect(onActivateClicked)
script.Parent.Parent.Shoot.ClickDetector.MouseClick:connect(onShootClicked)
0
It didn't work though. When I clicked the part didn't even go down. RobotChitti 167 — 5y
1
You make the part go down your self^^!!!common sense!!!... User#19524 175 — 5y
1
Did you add the extra code to include the variables and the CFrame movement? I only included half the code to show you what to change. You have to fill in the rest. Phantom1996 45 — 5y
0
Oh okay. I see. I'm sorry! RobotChitti 167 — 5y
Ad

Answer this question