Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

How can I make a vehicle the stops when a part is no longer connected to the rest of the vehicle?

Asked by 4 months ago

I want the vehicle to stop working when the "required" part is disconnected from the rest of the vehicle. I tried doing so by using :FindFirstChild("Weld"), but even if I delete the welds the script continues to move the vehicle. Shouldn't the FindFirstChild return nil when I delete the welds?

--Movement variables.
local move = script.Parent
local partMoving = false
local rotation = 0
local mode = "Forwards"
local movementY
local working = true

--Part required to run.
local required = script.Parent.Parent.Require

--Variables for the buttons.
local downBtn = script.Parent.Parent.Console.Down
local upBtn = script.Parent.Parent.Console.Up
local leftBtn = script.Parent.Parent.Console.Left
local rightBtn = script.Parent.Parent.Console.Right
local modeBtn = script.Parent.Parent.Console.Mode
local ignitionBtn = script.Parent.Parent.Console.Movement

--Sets the movement mode.
modeBtn.ClickDetector.MouseClick:Connect(function()
    if not partMoving then
        if mode == "Forwards" then
            mode = "Reverse"
            modeBtn.BrickColor = BrickColor.new("Eggplant")
        else
            mode = "Forwards"
            modeBtn.BrickColor = BrickColor.new("Cyan")
        end
    end
end)

--Starts or stops movement.
ignitionBtn.ClickDetector.MouseClick:Connect(function()
    if not partMoving then
        partMoving = true
        ignitionBtn.BrickColor = BrickColor.new("Lime green")
    else
        partMoving = false
        ignitionBtn.BrickColor = BrickColor.new("Really red")
    end
end)

--Sets the movement rotation
rightBtn.ClickDetector.MouseClick:Connect(function()
    rotation = -1
    wait(.3)
    rotation = 0
end)

leftBtn.ClickDetector.MouseClick:Connect(function()
    rotation = 1
    wait(.3)
    rotation = 0
end)

--Sets vertical movement
upBtn.ClickDetector.MouseClick:Connect(function()
    movementY = .5
    wait(.4)
    movementY = 0
end)

downBtn.ClickDetector.MouseClick:Connect(function()
    movementY = -.5
    wait(.4)
    movementY = 0
end)

--Moves "Move" based on the previously set instructions
---[[
required:WaitForChild("RequiredWeld")
while true do
    if script.Parent.Parent.Require:FindFirstChild("RequiredWeld") ~= nil then
        if partMoving then
            print ("Should be moving!")
            if mode == "Forwards" then
                move.CFrame = move.CFrame*CFrame.new(0,movementY,-.1) *CFrame.Angles(0,math.rad(rotation),0)
                wait (0.001)
            else
                move.CFrame = move.CFrame*CFrame.new(0,movementY,.1) *CFrame.Angles(0,math.rad(rotation),0)
                wait (0.001)
            end

        else
            wait (0.5)
        end
    else
        ignitionBtn.Material = "Glass"
        ignitionBtn.ClickDetector:Destroy()
        ignitionBtn.BrickColor = BrickColor.new("Maroon")
        --[[for i = 0, 10 do
            move.CFrame = CFrame.new(0,-.1,0) *CFrame.Angles(math.rad(-1),0,0)
            wait (0.001)
        end
        working = false
        while working == false do
            wait(.1)
            move.CFrame = CFrame.new(0,-.1,0)
        end
        --]]
    end
end
--]]


0
Try moving the part  sideways that has the  weld and delete it as well Markdrg 15 — 4mo
0
Try doing :ChildRemoved() IiTossiI -2 — 4mo
0
Child removed worked, if you add it as an answer I'll accept it. JarFullOfMayonnaise 33 — 4mo

Answer this question