Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why isn't this conditional statement work properly?

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

✓ Accepted answer

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 comment

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'.

This discussion is preserved as it was. New answers, comments, and votes are closed.