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

what does it mean if 'else' is underlined in red and how do i fix it?

This is the script:

local UIS = game:GetService("UserInputService") local plr = game.Players.LocalPlayer local char = plr.Character or plr.CharacterAdded:Wait()

local debounce = false

KeysDown={}

UIS.InputBegan:Connect(function(input,gpe) if gpe then return end if input.KeyCode == Enum.KeyCode.Q then if not debounce then debounce = true print("made true")

		if KeysDown.W then
			local animation = Char.Humanoid:LoadAnimation(script.FrontDash):Play()
			wait(0.3)
			Char.HumanoidRootPart.Velocity = Char.HumanoidRootPart.CFrame.lookVector* 150
			
			
		elseif KeysDown.D then
			--
			local animation = Char.Humanoid:LoadAnimation(script.RightDash):Play()
			wait(0.3)
			Char.HumanoidRootPart.Velocity = Char.HumanoidRootPart.CFrame.lookVector* 150
			
			
			
		elseif KeysDown.A then
		--
			local animation = Char.Humanoid:LoadAnimation(script.LeftDash):Play()
			wait(0.3)
			Char.HumanoidRootPart.Velocity = Char.HumanoidRootPart.CFrame.lookVector* -150
			
			
		elseif KeysDown.S then
			local animation = Char.Humanoid:LoadAnimation(script.BackDash):Play()
			wait(0.3)
			Char.HumanoidRootPart.Velocity = Char.HumanoidRootPart.CFrame.LookVector* -150
			
			
		end
		
		
	    end
	
	    wait(2)
	    debounce = false
	    print("made false")
     end
 else

 KeysDown[input.KeyCode.Name]=true
end

end)

UIS.InputEnded:Connect(function(input) if input.UserInputType == Enum.UserInputType.Keyboard then KeysDown[input.KeyCode.Name] = nil end end)

2 comments

0

else on line 37 is underlined in red

0

maybe because there is an "end" right before the else?

1 answer

When anything is underlined red it typically means that that variable isn't defined, or the statement is invalid. Your problem is you are trying to call else without an if statement.

local UIS = game:GetService("UserInputService") local plr = game.Players.LocalPlayer local char = plr.Character or plr.CharacterAdded:Wait()

local debounce = false

KeysDown={}

UIS.InputBegan:Connect(function(input,gpe) 
	if gpe then return end 
	if input.KeyCode == Enum.KeyCode.Q then 
		if not debounce then 
			debounce = true 
			print("made true")
			if KeysDown.W then
				local animation = Char.Humanoid:LoadAnimation(script.FrontDash):Play()
				wait(0.3)
				Char.HumanoidRootPart.Velocity = Char.HumanoidRootPart.CFrame.lookVector* 150


			elseif KeysDown.D then
				--
				local animation = Char.Humanoid:LoadAnimation(script.RightDash):Play()
				wait(0.3)
				Char.HumanoidRootPart.Velocity = Char.HumanoidRootPart.CFrame.lookVector* 150



			elseif KeysDown.A then
				--
				local animation = Char.Humanoid:LoadAnimation(script.LeftDash):Play()
				wait(0.3)
				Char.HumanoidRootPart.Velocity = Char.HumanoidRootPart.CFrame.lookVector* -150


			elseif KeysDown.S then
				local animation = Char.Humanoid:LoadAnimation(script.BackDash):Play()
				wait(0.3)
				Char.HumanoidRootPart.Velocity = Char.HumanoidRootPart.CFrame.LookVector* -150

			end

		end

		wait(2)
		debounce = false
		print("made false")
	else -- Else is used with if statements, nothing else. Basically when the if statement isn't true, it will continue with the else statements. In your case the script is detecting if the keypress is Q. If it is Q, see if W is held. If W isn't held check S, if S isn't held Check D, if D isn't held check A. If none of those are true then you run this else statement, but you ended the key check before you defined what else to do.
		KeysDown[input.KeyCode.Name]=true
	end
end

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