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

Why isn't this conditional statement work properly?

Asked by 10 years ago

For some reason line 17 won't run at all,why?

local BlueBar = script.Parent.GAME.BluPdl
local RedBar = script.Parent.GAME.RedPdl
local BlueSeat = script.Parent.Parent.Parent.Parent.BlueSeat
local RedSeat = script.Parent.Parent.Parent.Parent.RedSeat
----------------------BlueSeat----------------------------
BlueSeat.ChildAdded:connect(function(Part)--Checks if a Player has been steated
    if Part.Name == "SeatWeld" and Part.Part1.Name =="HumanoidRootPart" then
    ---------------------Vairbles-------------------------
    local Character = Part.Part1.Parent
    local Player = game.Players:GetPlayerFromCharacter(Character)
    local PlayersMouse = Player:GetMouse()
    ------------------------------------------------------
    PlayersMouse.KeyDown:connect(function(Key)
            if Key == "w" then
                if BlueBar.Position.Y.Offset > 0 then -- Rise Up if pressed w
                    BlueBar.Position = UDim2.new(0, 0, 0, (BlueBar.Position.Y.Offset - 20))
                elseif Key == "s" then
                    print("hi")--Test
                end
            end
        end)
    end
end)

I was testing if I did something wrong and made another script and it works but the one above won't and there almost the same.

Seat = script.Parent
    Seat.ChildAdded:connect(function(Part)
        if Part.Name == "SeatWeld" and Part.Part1.Name =="HumanoidRootPart" then
            Character = Part.Part1.Parent
            Player = game.Players:GetPlayerFromCharacter(Character)
            PlayersMouse = Player:GetMouse()
                PlayersMouse.KeyDown:connect(function(Key)
                if Key == "s" then
                    print(Key)
                end
            end)
        end
    end)

1 answer

Log in to vote
2
Answered by
Sparker22 190
10 years ago

Try this. You put your elseif Key if statement inside your BlueBar if statement on accident. I tabbed your code a little better and ended your BlueBar conditional statement before it checks for the "s" key.

local BlueBar = script.Parent.GAME.BluPdl
local RedBar = script.Parent.GAME.RedPdl
local BlueSeat = script.Parent.Parent.Parent.Parent.BlueSeat
local RedSeat = script.Parent.Parent.Parent.Parent.RedSeat
----------------------BlueSeat----------------------------
BlueSeat.ChildAdded:connect(function(Part)--Checks if a Player has been steated
    if Part.Name == "SeatWeld" and Part.Part1.Name =="HumanoidRootPart" then
    ---------------------Variables-------------------------
        local Character = Part.Part1.Parent
        local Player = game.Players:GetPlayerFromCharacter(Character)
        local PlayersMouse = Player:GetMouse()
    ------------------------------------------------------
        PlayersMouse.KeyDown:connect(function(Key)
            if Key == "w" then
                if BlueBar.Position.Y.Offset > 0 then -- Rise Up if pressed w
                    BlueBar.Position = UDim2.new(0, 0, 0, (BlueBar.Position.Y.Offset - 20))
                end
            elseif Key == "s" then
                print("hi")--Test
            end
        end)
    end
end)


1
To clarify the mistake, OP, you checked if the key was 's' *inside* of the block that only runs if the key is 'w'. adark 5487 — 10y
Ad

Answer this question